@@ -2,10 +2,9 @@ local utils = require("nvim-tree.utils")
2
2
3
3
local M = {}
4
4
5
- M .View = {
6
- tabpages = {},
7
- cursors = {},
8
- }
5
+ local BUFNR_PER_TAB = {}
6
+ local CURSORS = {}
7
+ local TABPAGES = {}
9
8
10
9
-- The initial state of a tab
11
10
local tabinitial = {
@@ -15,8 +14,6 @@ local tabinitial = {
15
14
winnr = nil ,
16
15
}
17
16
18
- local BUFNR_PER_TAB = {}
19
-
20
17
--- @param bufnr integer
21
18
--- @return boolean
22
19
local function matches_bufnr (bufnr )
48
45
--- @param tabpage integer
49
46
function M .setup_tabpage (tabpage )
50
47
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 })
52
49
end
53
50
54
51
-- save_tab_state saves any state that should be preserved across redraws.
55
52
--- @param tabnr integer
56
53
function M .save_tab_state (tabnr )
57
54
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 )
59
56
end
60
57
61
58
--- @param fn fun ( tabpage : integer )
62
59
function M .all_tabs_callback (fn )
63
- for tabpage , _ in pairs (M . View . tabpages ) do
60
+ for tabpage , _ in pairs (TABPAGES ) do
64
61
fn (tabpage )
65
62
end
66
63
end
67
64
68
65
function M .set_current_win ()
69
66
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 ()
71
68
end
72
69
73
70
function M .abandon_current_window ()
74
71
local tab = vim .api .nvim_get_current_tabpage ()
75
72
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
78
75
end
79
76
end
80
77
81
78
function M .abandon_all_windows ()
82
79
for tab , _ in pairs (vim .api .nvim_list_tabpages ()) do
83
80
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
86
83
end
87
84
end
88
85
end
91
88
--- @return boolean
92
89
function M .is_visible (opts )
93
90
if opts and opts .tabpage then
94
- if M . View . tabpages [opts .tabpage ] == nil then
91
+ if TABPAGES [opts .tabpage ] == nil then
95
92
return false
96
93
end
97
- local winnr = M . View . tabpages [opts .tabpage ].winnr
94
+ local winnr = TABPAGES [opts .tabpage ].winnr
98
95
return winnr and vim .api .nvim_win_is_valid (winnr )
99
96
end
100
97
101
98
if opts and opts .any_tabpage then
102
- for _ , v in pairs (M . View . tabpages ) do
99
+ for _ , v in pairs (TABPAGES ) do
103
100
if v .winnr and vim .api .nvim_win_is_valid (v .winnr ) then
104
101
return true
105
102
end
@@ -135,15 +132,15 @@ end
135
132
--- Restores the state of a NvimTree window if it was initialized before.
136
133
function M .restore_tab_state ()
137
134
local tabpage = vim .api .nvim_get_current_tabpage ()
138
- M .set_cursor (M . View . cursors [tabpage ])
135
+ M .set_cursor (CURSORS [tabpage ])
139
136
end
140
137
141
138
--- Returns the window number for nvim-tree within the tabpage specified
142
139
--- @param tabpage number | nil (optional ) the number of the chosen tabpage. Defaults to current tabpage.
143
140
--- @return number | nil
144
141
function M .get_winnr (tabpage )
145
142
tabpage = tabpage or vim .api .nvim_get_current_tabpage ()
146
- local tabinfo = M . View . tabpages [tabpage ]
143
+ local tabinfo = TABPAGES [tabpage ]
147
144
if tabinfo and tabinfo .winnr and vim .api .nvim_win_is_valid (tabinfo .winnr ) then
148
145
return tabinfo .winnr
149
146
end
@@ -157,30 +154,12 @@ end
157
154
158
155
--- @param winnr number | nil
159
156
function M .clear_tabpage (winnr )
160
- for i , tabpage in ipairs (M . View . tabpages ) do
157
+ for i , tabpage in ipairs (TABPAGES ) do
161
158
if tabpage .winnr == winnr then
162
- M . View . tabpages [i ] = nil
159
+ TABPAGES [i ] = nil
163
160
break
164
161
end
165
162
end
166
163
end
167
164
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
-
186
165
return M
0 commit comments