Skip to content

Commit 8c996a7

Browse files
committed
refactor(#2731): resolve warnings
1 parent b2dc803 commit 8c996a7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lua/nvim-tree/view.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ end
204204
---@param tabnr integer
205205
local function save_tab_state(tabnr)
206206
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)
208208
end
209209

210210
---@param tabpage integer
@@ -222,8 +222,8 @@ local function close(tabpage)
222222
if tree_win == current_win and prev_win > 0 then
223223
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
224224
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)
227227
end
228228
events._dispatch_on_tree_close()
229229
return
@@ -343,7 +343,7 @@ function M.resize(size)
343343
end
344344

345345
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)
347347

348348
-- TODO #1545 remove similar check from setup_autocommands
349349
-- We let nvim handle sending resize events after 0.9
@@ -420,7 +420,7 @@ function M.is_visible(opts)
420420
return false
421421
end
422422

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)
424424
end
425425

426426
---@param opts table|nil
@@ -443,7 +443,9 @@ function M.focus(winnr, open_if_closed)
443443
M.open()
444444
end
445445

446-
vim.api.nvim_set_current_win(wnr)
446+
if wnr then
447+
vim.api.nvim_set_current_win(wnr)
448+
end
447449
end
448450

449451
--- Retrieve the winid of the open tree.
@@ -541,7 +543,8 @@ end
541543

542544
-- used on ColorScheme event
543545
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
545548
vim.wo[M.get_winnr()].winhl = M.View.winopts.winhl
546549
end
547550
end

0 commit comments

Comments
 (0)