Skip to content

Commit d24f959

Browse files
committed
refactor(#2826): remove unnecessary view setup and members
1 parent 8b9c9c1 commit d24f959

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

lua/nvim-tree/view.lua

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ local utils = require("nvim-tree.utils")
22

33
local M = {}
44

5-
M.View = {
6-
tabpages = {},
7-
cursors = {},
8-
}
5+
local BUFNR_PER_TAB = {}
6+
local CURSORS = {}
7+
local TABPAGES = {}
98

109
-- The initial state of a tab
1110
local tabinitial = {
@@ -15,8 +14,6 @@ local tabinitial = {
1514
winnr = nil,
1615
}
1716

18-
local BUFNR_PER_TAB = {}
19-
2017
---@param bufnr integer
2118
---@return boolean
2219
local function matches_bufnr(bufnr)
@@ -48,41 +45,41 @@ end
4845
---@param tabpage integer
4946
function M.setup_tabpage(tabpage)
5047
local winnr = vim.api.nvim_get_current_win()
51-
M.View.tabpages[tabpage] = vim.tbl_extend("force", M.View.tabpages[tabpage] or tabinitial, { winnr = winnr })
48+
TABPAGES[tabpage] = vim.tbl_extend("force", TABPAGES[tabpage] or tabinitial, { winnr = winnr })
5249
end
5350

5451
-- save_tab_state saves any state that should be preserved across redraws.
5552
---@param tabnr integer
5653
function M.save_tab_state(tabnr)
5754
local tabpage = tabnr or vim.api.nvim_get_current_tabpage()
58-
M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr(tabpage) or 0)
55+
CURSORS[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr(tabpage) or 0)
5956
end
6057

6158
---@param fn fun(tabpage: integer)
6259
function M.all_tabs_callback(fn)
63-
for tabpage, _ in pairs(M.View.tabpages) do
60+
for tabpage, _ in pairs(TABPAGES) do
6461
fn(tabpage)
6562
end
6663
end
6764

6865
function M.set_current_win()
6966
local current_tab = vim.api.nvim_get_current_tabpage()
70-
M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win()
67+
TABPAGES[current_tab].winnr = vim.api.nvim_get_current_win()
7168
end
7269

7370
function M.abandon_current_window()
7471
local tab = vim.api.nvim_get_current_tabpage()
7572
BUFNR_PER_TAB[tab] = nil
76-
if M.View.tabpages[tab] then
77-
M.View.tabpages[tab].winnr = nil
73+
if TABPAGES[tab] then
74+
TABPAGES[tab].winnr = nil
7875
end
7976
end
8077

8178
function M.abandon_all_windows()
8279
for tab, _ in pairs(vim.api.nvim_list_tabpages()) do
8380
BUFNR_PER_TAB[tab] = nil
84-
if M.View.tabpages[tab] then
85-
M.View.tabpages[tab].winnr = nil
81+
if TABPAGES[tab] then
82+
TABPAGES[tab].winnr = nil
8683
end
8784
end
8885
end
@@ -91,15 +88,15 @@ end
9188
---@return boolean
9289
function M.is_visible(opts)
9390
if opts and opts.tabpage then
94-
if M.View.tabpages[opts.tabpage] == nil then
91+
if TABPAGES[opts.tabpage] == nil then
9592
return false
9693
end
97-
local winnr = M.View.tabpages[opts.tabpage].winnr
94+
local winnr = TABPAGES[opts.tabpage].winnr
9895
return winnr and vim.api.nvim_win_is_valid(winnr)
9996
end
10097

10198
if opts and opts.any_tabpage then
102-
for _, v in pairs(M.View.tabpages) do
99+
for _, v in pairs(TABPAGES) do
103100
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
104101
return true
105102
end
@@ -135,15 +132,15 @@ end
135132
--- Restores the state of a NvimTree window if it was initialized before.
136133
function M.restore_tab_state()
137134
local tabpage = vim.api.nvim_get_current_tabpage()
138-
M.set_cursor(M.View.cursors[tabpage])
135+
M.set_cursor(CURSORS[tabpage])
139136
end
140137

141138
--- Returns the window number for nvim-tree within the tabpage specified
142139
---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
143140
---@return number|nil
144141
function M.get_winnr(tabpage)
145142
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
146-
local tabinfo = M.View.tabpages[tabpage]
143+
local tabinfo = TABPAGES[tabpage]
147144
if tabinfo and tabinfo.winnr and vim.api.nvim_win_is_valid(tabinfo.winnr) then
148145
return tabinfo.winnr
149146
end
@@ -157,30 +154,12 @@ end
157154

158155
---@param winnr number|nil
159156
function M.clear_tabpage(winnr)
160-
for i, tabpage in ipairs(M.View.tabpages) do
157+
for i, tabpage in ipairs(TABPAGES) do
161158
if tabpage.winnr == winnr then
162-
M.View.tabpages[i] = nil
159+
TABPAGES[i] = nil
163160
break
164161
end
165162
end
166163
end
167164

168-
function M.setup(opts)
169-
local options = opts.view or {}
170-
M.View.centralize_selection = options.centralize_selection
171-
M.View.side = (options.side == "right") and "right" or "left"
172-
M.View.height = options.height
173-
M.View.hide_root_folder = opts.renderer.root_folder_label == false
174-
M.View.tab = opts.tab
175-
M.View.preserve_window_proportions = options.preserve_window_proportions
176-
M.View.winopts.cursorline = options.cursorline
177-
M.View.winopts.number = options.number
178-
M.View.winopts.relativenumber = options.relativenumber
179-
M.View.winopts.signcolumn = options.signcolumn
180-
M.View.float = options.float
181-
M.on_attach = opts.on_attach
182-
183-
M.config = options
184-
end
185-
186165
return M

0 commit comments

Comments
 (0)