@@ -18,7 +18,10 @@ local Class = require("nvim-tree.classic")
18
18
--- @field private width (fun (): integer )| integer | string
19
19
--- @field private max_width integer
20
20
--- @field private padding integer
21
- --- @field private bufnr_by_tabid table<integer , integer> stored per tab until multi-instance is complete
21
+ -- TODO multi-instance remove or replace with single member
22
+ --- @field private bufnr_by_tabid table<integer , integer>
23
+ -- TODO multi-instance change to single member
24
+ --- @field private cursors_by_tabid table<integer , integer[]> as per vim.api.nvim_win_get_cursor
22
25
local View = Class :extend ()
23
26
24
27
--- @class View
@@ -32,13 +35,14 @@ local View = Class:extend()
32
35
function View :new (args )
33
36
args .explorer :log_new (" View" )
34
37
35
- self .explorer = args .explorer
36
- self .adaptive_size = false
37
- self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
38
- self .live_filter = { prev_focused_node = nil , }
39
- self .bufnr_by_tabid = {}
38
+ self .explorer = args .explorer
39
+ self .adaptive_size = false
40
+ self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
41
+ self .live_filter = { prev_focused_node = nil , }
42
+ self .bufnr_by_tabid = {}
43
+ self .cursors_by_tabid = {}
40
44
41
- self .winopts = {
45
+ self .winopts = {
42
46
relativenumber = self .explorer .opts .view .relativenumber ,
43
47
number = self .explorer .opts .view .number ,
44
48
list = false ,
@@ -235,12 +239,12 @@ local function switch_buf_if_last_buf()
235
239
end
236
240
end
237
241
238
- --- save_tab_state saves any state that should be preserved across redraws.
242
+ --- save any state that should be preserved on reopening
239
243
--- @private
240
244
--- @param tabid integer
241
- function View :save_tab_state (tabid )
245
+ function View :save_state (tabid )
242
246
tabid = tabid or vim .api .nvim_get_current_tabpage ()
243
- globals . CURSORS [tabid ] = vim .api .nvim_win_get_cursor (self :get_winid (tabid , " View:save_tab_state" ) or 0 )
247
+ self . cursors_by_tabid [tabid ] = vim .api .nvim_win_get_cursor (self :get_winid (tabid , " View:save_tab_state" ) or 0 )
244
248
end
245
249
246
250
--- @private
@@ -255,7 +259,7 @@ function View:close_internal(tabid)
255
259
if not self :is_visible ({ tabpage = tabid }, " View:close_internal" ) then
256
260
return
257
261
end
258
- self :save_tab_state (tabid )
262
+ self :save_state (tabid )
259
263
switch_buf_if_last_buf ()
260
264
local tree_win = self :get_winid (tabid , " View:close_internal" )
261
265
local current_win = vim .api .nvim_get_current_win ()
@@ -608,9 +612,9 @@ function View:api_winid(opts)
608
612
end
609
613
end
610
614
611
- --- Restores the state of a NvimTree window if it was initialized before.
612
- function View :restore_tab_state ()
613
- self :set_cursor (globals . CURSORS [vim .api .nvim_get_current_tabpage ()])
615
+ --- restore any state from last close
616
+ function View :restore_state ()
617
+ self :set_cursor (self . cursors_by_tabid [vim .api .nvim_get_current_tabpage ()])
614
618
end
615
619
616
620
--- winid containing the buffer
0 commit comments