From 82cc80ffa435c9f47c0244007e3af139cc915ae0 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 20 Jun 2025 12:47:04 +1000 Subject: [PATCH] Revert "refactor(#2826): move global CURSORS to view member" This reverts commit d84dfad1c368a44767044f20cc35f0c41c17a2b2. --- lua/nvim-tree/explorer/view.lua | 11 +++++------ lua/nvim-tree/globals.lua | 1 + lua/nvim-tree/lib.lua | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/explorer/view.lua b/lua/nvim-tree/explorer/view.lua index a3e6d900..0cbdb899 100644 --- a/lua/nvim-tree/explorer/view.lua +++ b/lua/nvim-tree/explorer/view.lua @@ -19,7 +19,6 @@ local Class = require("nvim-tree.classic") ---@field private max_width integer ---@field private padding integer ---@field private bufnr_by_tabid table stored per tab until multi-instance is complete ----@field private cursor integer[] as per vim.api.nvim_win_get_cursor local View = Class:extend() ---@class View @@ -236,12 +235,12 @@ local function switch_buf_if_last_buf() end end ----save any state that should be preserved on reopening +---save_tab_state saves any state that should be preserved across redraws. ---@private ---@param tabid integer function View:save_tab_state(tabid) tabid = tabid or vim.api.nvim_get_current_tabpage() - self.cursor = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0) + globals.CURSORS[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0) end ---@private @@ -609,9 +608,9 @@ function View:api_winid(opts) end end ---- restore any state from last close -function View:restore_state() - self:set_cursor(self.cursor) +--- Restores the state of a NvimTree window if it was initialized before. +function View:restore_tab_state() + self:set_cursor(globals.CURSORS[vim.api.nvim_get_current_tabpage()]) end --- winid containing the buffer diff --git a/lua/nvim-tree/globals.lua b/lua/nvim-tree/globals.lua index a2ab7527..66211260 100644 --- a/lua/nvim-tree/globals.lua +++ b/lua/nvim-tree/globals.lua @@ -4,6 +4,7 @@ local M = { -- from View WINID_BY_TABID = {}, BUFNR_BY_TABID = {}, + CURSORS = {}, } return M diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 6c1ef1ef..854e33bf 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -135,8 +135,9 @@ function M.open(opts) open_view_and_draw() end + -- TODO multi-instance is this actually necessary? if explorer then - explorer.view:restore_state() + explorer.view:restore_tab_state() end end