Skip to content

Commit 2d89ca9

Browse files
authored
fix: improve safety of window_exists function (#1136)
1 parent 71d5559 commit 2d89ca9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lua/neo-tree/ui/renderer.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,13 +1090,20 @@ M.window_exists = function(state)
10901090
local isvalid = M.is_window_valid(winid)
10911091
window_exists = isvalid and (vim.api.nvim_win_get_number(winid) > 0)
10921092
if window_exists then
1093-
local bufnr = vim.api.nvim_win_get_buf(winid)
1094-
if bufnr > 0 and bufnr ~= state.bufnr then
1095-
window_exists = false
1096-
end
1097-
local buf_position = vim.api.nvim_buf_get_var(bufnr, "neo_tree_position")
1098-
if buf_position ~= position then
1099-
window_exists = false
1093+
local winbufnr = vim.api.nvim_win_get_buf(winid)
1094+
if winbufnr < 1 then
1095+
return false
1096+
else
1097+
if winbufnr ~= bufnr then
1098+
return false
1099+
end
1100+
local success, buf_position = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_position")
1101+
if not success then
1102+
return false
1103+
end
1104+
if buf_position ~= position then
1105+
return false
1106+
end
11001107
end
11011108
end
11021109
end

0 commit comments

Comments
 (0)