@@ -85,7 +85,7 @@ function OrgFile:reload()
8585 local bufnr = self :bufnr ()
8686
8787 if bufnr > - 1 then
88- local updated_file = self :_update_lines (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ))
88+ local updated_file = self :_update_lines (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ), bufnr )
8989 return Promise .resolve (updated_file )
9090 end
9191
@@ -109,17 +109,13 @@ function OrgFile:is_modified()
109109 local bufnr = self :bufnr ()
110110 if bufnr > - 1 then
111111 local cur_changedtick = vim .api .nvim_buf_get_changedtick (bufnr )
112- local is_changed = cur_changedtick ~= self .metadata .changedtick
113- self .metadata .changedtick = cur_changedtick
114- return is_changed
112+ return cur_changedtick ~= self .metadata .changedtick
115113 end
116114 local stat = vim .loop .fs_stat (self .filename )
117115 if not stat then
118116 return false
119117 end
120- local is_changed = stat .mtime .nsec ~= self .metadata .mtime
121- self .metadata .mtime = stat .mtime .nsec
122- return is_changed
118+ return stat .mtime .nsec ~= self .metadata .mtime
123119end
124120
125121--- Parse the file and update the root node
@@ -646,10 +642,16 @@ end
646642
647643--- @private
648644--- @param lines string[]
649- function OrgFile :_update_lines (lines )
645+ --- @param bufnr ? number
646+ function OrgFile :_update_lines (lines , bufnr )
650647 self .lines = lines
651648 self .content = table.concat (lines , ' \n ' )
652649 self :parse ()
650+ if bufnr then
651+ self .metadata .changedtick = vim .api .nvim_buf_get_changedtick (bufnr )
652+ else
653+ self .metadata .mtime = vim .loop .fs_stat (self .filename ).mtime .nsec
654+ end
653655 return self
654656end
655657
0 commit comments