Skip to content

Commit f275d3f

Browse files
authored
fix(view): Fix error thrown when trying to wipe buffer in autocmd window. (#314)
1 parent 783870c commit f275d3f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lua/nvim-tree/view.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ M.View = {
6868
---Find a rogue NvimTree buffer that might have been spawned by i.e. a session.
6969
---@return integer|nil
7070
local function find_rogue_buffer()
71-
for i = 1, vim.fn.bufnr("$"), 1 do
72-
if vim.fn.bufname(i) == "NvimTree" then
73-
return i
71+
for _, v in ipairs(a.nvim_list_bufs()) do
72+
if vim.fn.bufname(v) == "NvimTree" then
73+
return v
7474
end
7575
end
7676
return nil
@@ -89,9 +89,14 @@ function M._wipe_rogue_buffer()
8989
if bn then
9090
local win_ids = vim.fn.win_findbuf(bn)
9191
for _, id in ipairs(win_ids) do
92-
a.nvim_win_close(id, true)
92+
if vim.fn.win_gettype(id) ~= "autocmd" then
93+
a.nvim_win_close(id, true)
94+
end
9395
end
94-
a.nvim_buf_delete(bn, {})
96+
97+
vim.schedule(function ()
98+
pcall(a.nvim_buf_delete, bn, {})
99+
end)
95100
end
96101
end
97102

0 commit comments

Comments
 (0)