Skip to content

fix: delete neo-tree buffers created by :mksession #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ local default_popup_size = { width = 60, height = "80%" }
local floating_windows = {}
local draw, create_window, create_tree, render_tree

-- clean up neotree buffers created by :mksession
local cleaned_up = false
local clean_neotree_buffers = function()
if cleaned_up then
return
end

for _, buf in ipairs(vim.api.nvim_list_bufs()) do
local bufname = vim.fn.bufname(buf)
if string.match(bufname, "neo%-tree [^ ]+ %[%d+]") then
vim.api.nvim_buf_delete(buf, { force = true })
end
end
cleaned_up = true
end

local resize_monitor_timer = nil
local start_resize_monitor = function()
local interval = M.resize_timer_interval or -1
Expand Down Expand Up @@ -805,6 +821,7 @@ create_window = function(state)
tabnr = state.tabnr,
}
events.fire_event(events.NEO_TREE_WINDOW_BEFORE_OPEN, event_args)
clean_neotree_buffers()

if state.current_position == "float" then
state.force_float = nil
Expand Down