@@ -688,16 +688,17 @@ end
688688--- Saves a window position to be restored later
689689--- @param state neotree.State
690690--- @param force boolean ?
691+ --- @return boolean saved
691692M .position .save = function (state , force )
692693 if not force and state .position .topline and state .position .lnum then
693694 log .debug (" There's already a position saved to be restored. Cannot save another." )
694- return
695+ return false
695696 end
696697 if not state .tree then
697- return
698+ return false
698699 end
699700 if not M .window_exists (state ) then
700- return
701+ return false
701702 end
702703
703704 local win_state = vim .api .nvim_win_call (state .winid , vim .fn .winsaveview )
@@ -713,6 +714,7 @@ M.position.save = function(state, force)
713714 local b = vim .fn .getpos (" v" )
714715 state .position .visual_selection = { a , b }
715716 end
717+ return true
716718end
717719
718720--- Queues a node to focus
@@ -1161,22 +1163,26 @@ M.acquire_window = function(state)
11611163 vim .api .nvim_buf_set_name (state .bufnr , bufname )
11621164 vim .api .nvim_set_current_win (state .winid )
11631165 -- Used to track the position of the cursor within the tree as it gains and loses focus
1164- local restored_after_window_change = false
1165- win :on ({ " CursorMoved" , " ModeChanged" }, function (args )
1166- if win .winid == vim .api .nvim_get_current_win () and restored_after_window_change then
1167- M .position .save (state , true )
1166+ local wait_for_save = true
1167+ win :on ({ " CursorMoved" , " ModeChanged" }, function ()
1168+ if state .winid == vim .api .nvim_get_current_win () then
1169+ if not wait_for_save then
1170+ M .position .save (state , true )
1171+ elseif M .position .save (state ) then
1172+ wait_for_save = false
1173+ end
11681174 end
11691175 end )
11701176 win :on ({ " BufDelete" }, function ()
11711177 M .position .save (state )
11721178 end )
1173- win :on ({ " WinEnter" }, function (args )
1179+ win :on ({ " WinEnter" }, function ()
11741180 M .position .restore_selection (state )
1175- if win .winid == vim .api .nvim_get_current_win () then
1181+ if state .winid == vim .api .nvim_get_current_win () then
11761182 M .position .restore (state )
1177- restored_after_window_change = true
1183+ wait_for_save = false
11781184 else
1179- restored_after_window_change = false
1185+ wait_for_save = true
11801186 end
11811187 end )
11821188 win :on ({ " BufDelete" }, function ()
0 commit comments