Skip to content

Commit 82cc80f

Browse files
committed
Revert "refactor(#2826): move global CURSORS to view member"
This reverts commit d84dfad.
1 parent d84dfad commit 82cc80f

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lua/nvim-tree/explorer/view.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ 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
2322
local View = Class:extend()
2423

2524
---@class View
@@ -236,12 +235,12 @@ local function switch_buf_if_last_buf()
236235
end
237236
end
238237

239-
---save any state that should be preserved on reopening
238+
---save_tab_state saves any state that should be preserved across redraws.
240239
---@private
241240
---@param tabid integer
242241
function View:save_tab_state(tabid)
243242
tabid = tabid or vim.api.nvim_get_current_tabpage()
244-
self.cursor = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
243+
globals.CURSORS[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
245244
end
246245

247246
---@private
@@ -609,9 +608,9 @@ function View:api_winid(opts)
609608
end
610609
end
611610

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

617616
--- winid containing the buffer

lua/nvim-tree/globals.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local M = {
44
-- from View
55
WINID_BY_TABID = {},
66
BUFNR_BY_TABID = {},
7+
CURSORS = {},
78
}
89

910
return M

lua/nvim-tree/lib.lua

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

138+
-- TODO multi-instance is this actually necessary?
138139
if explorer then
139-
explorer.view:restore_state()
140+
explorer.view:restore_tab_state()
140141
end
141142
end
142143

0 commit comments

Comments
 (0)