Skip to content

Commit c61074a

Browse files
authored
fix: revert window close buffer cleanup code (#1433)
fixes #1415
1 parent 6604275 commit c61074a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lua/neo-tree/ui/renderer.lua

+14-13
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ M.close = function(state, focus_prior_window)
136136
end
137137
vim.api.nvim_win_set_buf(state.winid, new_buf)
138138
else
139+
local args = {
140+
position = state.current_position,
141+
source = state.name,
142+
winid = state.winid,
143+
tabnr = tabid_to_tabnr(state.tabid), -- for compatibility
144+
tabid = state.tabid,
145+
}
139146
events.fire_event(events.NEO_TREE_WINDOW_BEFORE_CLOSE, args)
140147
local win_list = vim.api.nvim_tabpage_list_wins(0)
141148
if focus_prior_window and #win_list > 1 then
142-
local args = {
143-
position = state.current_position,
144-
source = state.name,
145-
winid = state.winid,
146-
tabnr = tabid_to_tabnr(state.tabid), -- for compatibility
147-
tabid = state.tabid,
148-
}
149149
-- focus the prior used window if we are closing the currently focused window
150150
local current_winid = vim.api.nvim_get_current_win()
151151
if current_winid == state.winid then
@@ -163,14 +163,15 @@ M.close = function(state, focus_prior_window)
163163
end
164164
state.winid = nil
165165
end
166-
if window_existed then
167-
local bufnr = utils.get_value(state, "bufnr", 0, true)
166+
local bufnr = utils.get_value(state, "bufnr", 0, true)
167+
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
168168
state.bufnr = nil
169-
vim.schedule(function()
170-
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then
169+
local success, err = pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
170+
if not success and err and err:match("E523") then
171+
vim.schedule_wrap(function()
171172
vim.api.nvim_buf_delete(bufnr, { force = true })
172-
end
173-
end)
173+
end)()
174+
end
174175
end
175176
return window_existed
176177
end

0 commit comments

Comments
 (0)