|
112 | 112 | ---@param state table State of the source to close |
113 | 113 | ---@param focus_prior_window boolean | nil if true or nil, focus the window that was previously focused |
114 | 114 | M.close = function(state, focus_prior_window) |
| 115 | + |
| 116 | + log.debug("Closing window, but saving position first.") |
| 117 | + M.position.save(state) |
| 118 | + |
115 | 119 | if focus_prior_window == nil then |
116 | 120 | focus_prior_window = true |
117 | 121 | end |
|
639 | 643 | ---Functions to save and restore the focused node. |
640 | 644 | M.position = { |
641 | 645 | save = function(state) |
| 646 | + if state.position.topline and state.position.lnum then |
| 647 | + log.debug("There's already a position saved to be restored. Cannot save another.") |
| 648 | + return |
| 649 | + end |
| 650 | + |
642 | 651 | if state.tree and M.window_exists(state) then |
643 | 652 | local win_state = vim.api.nvim_win_call(state.winid, vim.fn.winsaveview) |
644 | 653 | state.position.topline = win_state.topline |
@@ -666,6 +675,9 @@ M.position = { |
666 | 675 | vim.api.nvim_win_call(state.winid, function() |
667 | 676 | vim.fn.winrestview({ topline = state.position.topline, lnum = state.position.lnum }) |
668 | 677 | end) |
| 678 | + -- Clear saved position, so that we can save another position later. |
| 679 | + state.position.topline = nil |
| 680 | + state.position.lnum = nil |
669 | 681 | end |
670 | 682 | if state.position.node_id then |
671 | 683 | log.debug("Focusing on node_id: " .. state.position.node_id) |
@@ -1218,9 +1230,6 @@ draw = function(nodes, state, parent_id) |
1218 | 1230 | -- draw winbar / statusbar |
1219 | 1231 | require("neo-tree.ui.selector").set_source_selector(state) |
1220 | 1232 |
|
1221 | | - -- Restore the cursor position/focused node in the tree based on the state |
1222 | | - -- when it was last closed |
1223 | | - M.position.restore(state) |
1224 | 1233 | state._ready = true |
1225 | 1234 | end |
1226 | 1235 |
|
|
0 commit comments