@@ -179,20 +179,20 @@ local function switch_buf_if_last_buf()
179
179
end
180
180
181
181
-- save_tab_state saves any state that should be preserved across redraws.
182
- local function save_tab_state ()
183
- local tabpage = vim .api .nvim_get_current_tabpage ()
184
- M .View .cursors [tabpage ] = vim .api .nvim_win_get_cursor (M .get_winnr ())
182
+ local function save_tab_state (tabnr )
183
+ local tabpage = tabnr or vim .api .nvim_get_current_tabpage ()
184
+ M .View .cursors [tabpage ] = vim .api .nvim_win_get_cursor (M .get_winnr (tabpage ))
185
185
end
186
186
187
- local function close (all_tabpages )
188
- if not M .is_visible () then
187
+ local function close (tabpage )
188
+ if not M .is_visible { tabpage = tabpage } then
189
189
return
190
190
end
191
- save_tab_state ()
191
+ save_tab_state (tabpage )
192
192
switch_buf_if_last_buf ()
193
- local tree_win = M .get_winnr ()
193
+ local tree_win = M .get_winnr (tabpage )
194
194
local current_win = vim .api .nvim_get_current_win ()
195
- for _ , win in pairs (vim .api .nvim_list_wins ( )) do
195
+ for _ , win in pairs (vim .api .nvim_tabpage_list_wins ( tabpage )) do
196
196
if tree_win ~= win and vim .api .nvim_win_get_config (win ).relative == " " then
197
197
local prev_win = vim .fn .winnr " #" -- this tab only
198
198
if tree_win == current_win and prev_win > 0 then
@@ -201,29 +201,28 @@ local function close(all_tabpages)
201
201
if vim .api .nvim_win_is_valid (tree_win ) then
202
202
vim .api .nvim_win_close (tree_win , true )
203
203
end
204
- if all_tabpages then
205
- for _ , v in pairs (M .View .tabpages ) do
206
- if v .winnr and vim .api .nvim_win_is_valid (v .winnr ) then
207
- vim .api .nvim_win_close (v .winnr , true )
208
- end
209
- end
210
- end
211
204
events ._dispatch_on_tree_close ()
212
205
return
213
206
end
214
207
end
215
208
end
216
209
217
210
function M .close_this_tab_only ()
218
- close (false )
211
+ close (vim . api . nvim_get_current_tabpage () )
219
212
end
220
213
221
214
function M .close_all_tabs ()
222
- close (true )
215
+ for tabpage , _ in pairs (M .View .tabpages ) do
216
+ close (tabpage )
217
+ end
223
218
end
224
219
225
220
function M .close ()
226
- close (M .View .tab .sync .close )
221
+ if M .View .tab .sync .close then
222
+ M .close_all_tabs ()
223
+ else
224
+ M .close_this_tab_only ()
225
+ end
227
226
end
228
227
229
228
function M .open (options )
@@ -331,6 +330,14 @@ function M.abandon_current_window()
331
330
end
332
331
333
332
function M .is_visible (opts )
333
+ if opts and opts .tabpage then
334
+ if M .View .tabpages [opts .tabpage ] == nil then
335
+ return false
336
+ end
337
+ local winnr = M .View .tabpages [opts .tabpage ].winnr
338
+ return winnr and vim .api .nvim_win_is_valid (winnr )
339
+ end
340
+
334
341
if opts and opts .any_tabpage then
335
342
for _ , v in pairs (M .View .tabpages ) do
336
343
if v .winnr and vim .api .nvim_win_is_valid (v .winnr ) then
0 commit comments