Skip to content

Commit

Permalink
fix(renderer): check if current buffer is loaded (#1406)
Browse files Browse the repository at this point in the history
Co-authored-by: cseickel <cseickel@gmail.com>
  • Loading branch information
pysan3 and cseickel committed Mar 21, 2024
1 parent 8afbb06 commit 16d1b19
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lua/neo-tree/ui/renderer.lua
Expand Up @@ -163,15 +163,14 @@ M.close = function(state, focus_prior_window)
end
state.winid = nil
end
local bufnr = utils.get_value(state, "bufnr", 0, true)
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
if window_existed then
local bufnr = utils.get_value(state, "bufnr", 0, true)
state.bufnr = nil
local success, err = pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
if not success and err:match("E523") then
vim.schedule_wrap(function()
vim.schedule(function()
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_delete(bufnr, { force = true })
end)()
end
end
end)
end
return window_existed
end
Expand Down Expand Up @@ -781,6 +780,7 @@ create_tree = function(state)
state.tree = NuiTree({
ns_id = highlights.ns_id,
winid = state.winid,
bufnr = state.bufnr,
get_node_id = function(node)
return node.id
end,
Expand Down Expand Up @@ -1090,7 +1090,7 @@ M.window_exists = function(state)
window_exists = false
elseif position == "current" then
window_exists = vim.api.nvim_win_is_valid(winid)
and vim.api.nvim_buf_is_valid(bufnr)
and vim.api.nvim_buf_is_loaded(bufnr)
and vim.api.nvim_win_get_buf(winid) == bufnr
else
local isvalid = M.is_window_valid(winid)
Expand Down

0 comments on commit 16d1b19

Please sign in to comment.