Skip to content

Commit d84dfad

Browse files
committed
refactor(#2826): move global CURSORS to view member
1 parent 4d6c423 commit d84dfad

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lua/nvim-tree/explorer/view.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ local Class = require("nvim-tree.classic")
1919
---@field private max_width integer
2020
---@field private padding integer
2121
---@field private bufnr_by_tabid table<integer, integer> stored per tab until multi-instance is complete
22+
---@field private cursor integer[] as per vim.api.nvim_win_get_cursor
2223
local View = Class:extend()
2324

2425
---@class View
@@ -235,12 +236,12 @@ local function switch_buf_if_last_buf()
235236
end
236237
end
237238

238-
---save_tab_state saves any state that should be preserved across redraws.
239+
---save any state that should be preserved on reopening
239240
---@private
240241
---@param tabid integer
241242
function View:save_tab_state(tabid)
242243
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)
244+
self.cursor = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
244245
end
245246

246247
---@private
@@ -608,9 +609,9 @@ function View:api_winid(opts)
608609
end
609610
end
610611

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()])
612+
--- restore any state from last close
613+
function View:restore_state()
614+
self:set_cursor(self.cursor)
614615
end
615616

616617
--- winid containing the buffer

lua/nvim-tree/globals.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ local M = {
44
-- from View
55
WINID_BY_TABID = {},
66
BUFNR_BY_TABID = {},
7-
CURSORS = {},
87
}
98

109
return M

lua/nvim-tree/lib.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ function M.open(opts)
135135
open_view_and_draw()
136136
end
137137

138-
-- TODO multi-instance is this actually necessary?
139138
if explorer then
140-
explorer.view:restore_tab_state()
139+
explorer.view:restore_state()
141140
end
142141
end
143142

0 commit comments

Comments
 (0)