204
204
--- @param tabnr integer
205
205
local function save_tab_state (tabnr )
206
206
local tabpage = tabnr or vim .api .nvim_get_current_tabpage ()
207
- M .View .cursors [tabpage ] = vim .api .nvim_win_get_cursor (M .get_winnr (tabpage ))
207
+ M .View .cursors [tabpage ] = vim .api .nvim_win_get_cursor (M .get_winnr (tabpage ) or 0 )
208
208
end
209
209
210
210
--- @param tabpage integer
@@ -222,8 +222,8 @@ local function close(tabpage)
222
222
if tree_win == current_win and prev_win > 0 then
223
223
vim .api .nvim_set_current_win (vim .fn .win_getid (prev_win ))
224
224
end
225
- if vim .api .nvim_win_is_valid (tree_win ) then
226
- vim .api .nvim_win_close (tree_win , true )
225
+ if vim .api .nvim_win_is_valid (tree_win or 0 ) then
226
+ vim .api .nvim_win_close (tree_win or 0 , true )
227
227
end
228
228
events ._dispatch_on_tree_close ()
229
229
return
@@ -343,7 +343,7 @@ function M.resize(size)
343
343
end
344
344
345
345
local new_size = get_width ()
346
- vim .api .nvim_win_set_width (M .get_winnr (), new_size )
346
+ vim .api .nvim_win_set_width (M .get_winnr () or 0 , new_size )
347
347
348
348
-- TODO #1545 remove similar check from setup_autocommands
349
349
-- We let nvim handle sending resize events after 0.9
@@ -420,7 +420,7 @@ function M.is_visible(opts)
420
420
return false
421
421
end
422
422
423
- return M .get_winnr () ~= nil and vim .api .nvim_win_is_valid (M .get_winnr ())
423
+ return M .get_winnr () ~= nil and vim .api .nvim_win_is_valid (M .get_winnr () or 0 )
424
424
end
425
425
426
426
--- @param opts table | nil
@@ -443,7 +443,9 @@ function M.focus(winnr, open_if_closed)
443
443
M .open ()
444
444
end
445
445
446
- vim .api .nvim_set_current_win (wnr )
446
+ if wnr then
447
+ vim .api .nvim_set_current_win (wnr )
448
+ end
447
449
end
448
450
449
451
--- Retrieve the winid of the open tree.
541
543
542
544
-- used on ColorScheme event
543
545
function M .reset_winhl ()
544
- if M .get_winnr () and vim .api .nvim_win_is_valid (M .get_winnr ()) then
546
+ local winnr = M .get_winnr ()
547
+ if winnr and vim .api .nvim_win_is_valid (winnr ) then
545
548
vim .wo [M .get_winnr ()].winhl = M .View .winopts .winhl
546
549
end
547
550
end
0 commit comments