refactor(#2826): move global CURSORS to view member
This commit is contained in:
parent
4d6c42356a
commit
d84dfad1c3
@ -19,6 +19,7 @@ local Class = require("nvim-tree.classic")
|
|||||||
---@field private max_width integer
|
---@field private max_width integer
|
||||||
---@field private padding integer
|
---@field private padding integer
|
||||||
---@field private bufnr_by_tabid table<integer, integer> stored per tab until multi-instance is complete
|
---@field private bufnr_by_tabid table<integer, integer> stored per tab until multi-instance is complete
|
||||||
|
---@field private cursor integer[] as per vim.api.nvim_win_get_cursor
|
||||||
local View = Class:extend()
|
local View = Class:extend()
|
||||||
|
|
||||||
---@class View
|
---@class View
|
||||||
@ -235,12 +236,12 @@ local function switch_buf_if_last_buf()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---save_tab_state saves any state that should be preserved across redraws.
|
---save any state that should be preserved on reopening
|
||||||
---@private
|
---@private
|
||||||
---@param tabid integer
|
---@param tabid integer
|
||||||
function View:save_tab_state(tabid)
|
function View:save_tab_state(tabid)
|
||||||
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
||||||
globals.CURSORS[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
|
self.cursor = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
@ -608,9 +609,9 @@ function View:api_winid(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Restores the state of a NvimTree window if it was initialized before.
|
--- restore any state from last close
|
||||||
function View:restore_tab_state()
|
function View:restore_state()
|
||||||
self:set_cursor(globals.CURSORS[vim.api.nvim_get_current_tabpage()])
|
self:set_cursor(self.cursor)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- winid containing the buffer
|
--- winid containing the buffer
|
||||||
|
|||||||
@ -4,7 +4,6 @@ local M = {
|
|||||||
-- from View
|
-- from View
|
||||||
WINID_BY_TABID = {},
|
WINID_BY_TABID = {},
|
||||||
BUFNR_BY_TABID = {},
|
BUFNR_BY_TABID = {},
|
||||||
CURSORS = {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -135,9 +135,8 @@ function M.open(opts)
|
|||||||
open_view_and_draw()
|
open_view_and_draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO multi-instance is this actually necessary?
|
|
||||||
if explorer then
|
if explorer then
|
||||||
explorer.view:restore_tab_state()
|
explorer.view:restore_state()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user