Skip to content

Commit

Permalink
fix: improve safety of window_exists function (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
cseickel committed Sep 5, 2023
1 parent 71d5559 commit 2d89ca9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1090,13 +1090,20 @@ M.window_exists = function(state)
local isvalid = M.is_window_valid(winid)
window_exists = isvalid and (vim.api.nvim_win_get_number(winid) > 0)
if window_exists then
local bufnr = vim.api.nvim_win_get_buf(winid)
if bufnr > 0 and bufnr ~= state.bufnr then
window_exists = false
end
local buf_position = vim.api.nvim_buf_get_var(bufnr, "neo_tree_position")
if buf_position ~= position then
window_exists = false
local winbufnr = vim.api.nvim_win_get_buf(winid)
if winbufnr < 1 then
return false
else
if winbufnr ~= bufnr then
return false
end
local success, buf_position = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_position")
if not success then
return false
end
if buf_position ~= position then
return false
end
end
end
end
Expand Down

0 comments on commit 2d89ca9

Please sign in to comment.