Skip to content

Commit f6e4133

Browse files
authored
fix: add neo-tree buffer valid check (#771)
1 parent 74040b3 commit f6e4133

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lua/neo-tree/sources/manager.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ end
122122
M.get_state_for_window = function(winid)
123123
local winid = winid or vim.api.nvim_get_current_win()
124124
local bufnr = vim.api.nvim_win_get_buf(winid)
125-
local _, source_name = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_source")
126-
local _, position = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_position")
127-
if not source_name or not position then
125+
local source_status, source_name = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_source")
126+
local position_status, position = pcall(vim.api.nvim_buf_get_var, bufnr, "neo_tree_position")
127+
if not source_status or not position_status then
128128
return nil
129129
end
130130

lua/neo-tree/ui/renderer.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ M.clean_invalid_neotree_buffers = function(force)
3737

3838
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
3939
local bufname = vim.fn.bufname(buf)
40-
if string.match(bufname, "neo%-tree [^ ]+ %[%d+]") then
40+
local is_neotree_buffer = string.match(bufname, "neo%-tree [^ ]+ %[%d+]")
41+
local is_valid_neotree, _ = pcall(vim.api.nvim_buf_get_var, buf, "neo_tree_source")
42+
if is_neotree_buffer and not is_valid_neotree then
4143
vim.api.nvim_buf_delete(buf, { force = true })
4244
end
4345
end

0 commit comments

Comments
 (0)