Skip to content

Commit 16d1b19

Browse files
pysan3cseickel
andauthored
fix(renderer): check if current buffer is loaded (#1406)
Co-authored-by: cseickel <[email protected]>
1 parent 8afbb06 commit 16d1b19

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lua/neo-tree/ui/renderer.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ M.close = function(state, focus_prior_window)
163163
end
164164
state.winid = nil
165165
end
166-
local bufnr = utils.get_value(state, "bufnr", 0, true)
167-
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
166+
if window_existed then
167+
local bufnr = utils.get_value(state, "bufnr", 0, true)
168168
state.bufnr = nil
169-
local success, err = pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
170-
if not success and err:match("E523") then
171-
vim.schedule_wrap(function()
169+
vim.schedule(function()
170+
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
172171
vim.api.nvim_buf_delete(bufnr, { force = true })
173-
end)()
174-
end
172+
end
173+
end)
175174
end
176175
return window_existed
177176
end
@@ -781,6 +780,7 @@ create_tree = function(state)
781780
state.tree = NuiTree({
782781
ns_id = highlights.ns_id,
783782
winid = state.winid,
783+
bufnr = state.bufnr,
784784
get_node_id = function(node)
785785
return node.id
786786
end,
@@ -1090,7 +1090,7 @@ M.window_exists = function(state)
10901090
window_exists = false
10911091
elseif position == "current" then
10921092
window_exists = vim.api.nvim_win_is_valid(winid)
1093-
and vim.api.nvim_buf_is_valid(bufnr)
1093+
and vim.api.nvim_buf_is_loaded(bufnr)
10941094
and vim.api.nvim_win_get_buf(winid) == bufnr
10951095
else
10961096
local isvalid = M.is_window_valid(winid)

0 commit comments

Comments
 (0)