Skip to content

fix(setup): subscribe neo-tree buffer cleanup to session load #761

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 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lua/neo-tree/events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local M = {
VIM_LEAVE = "vim_leave",
VIM_RESIZED = "vim_resized",
VIM_CURSOR_MOVED = "vim_cursor_moved",
VIM_AFTER_SESSION_LOAD = "vim_after_session_load",
}

M.define_autocmd_event = function(event_name, autocmds, debounce_frequency, seed_fn, nested)
Expand Down
8 changes: 8 additions & 0 deletions lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local define_events = function()
events.define_autocmd_event(events.VIM_WIN_CLOSED, { "WinClosed" })
events.define_autocmd_event(events.VIM_COLORSCHEME, { "ColorScheme" }, 0)
events.define_autocmd_event(events.VIM_CURSOR_MOVED, { "CursorMoved" }, 100)
events.define_autocmd_event(events.VIM_AFTER_SESSION_LOAD, { "SessionLoadPost" }, 200)
events.define_autocmd_event(events.GIT_EVENT, { "User FugitiveChanged" }, 100)
events.define_event(events.GIT_STATUS_CHANGED, { debounce_frequency = 0 })
events_setup = true
Expand All @@ -93,6 +94,13 @@ local define_events = function()
require("neo-tree.ui.renderer").update_floating_window_layouts()
end,
})

events.subscribe({
event = events.VIM_AFTER_SESSION_LOAD,
handler = function()
require("neo-tree.ui.renderer").clean_invalid_neotree_buffers(true)
end,
})
end

local prior_window_options = {}
Expand Down
9 changes: 5 additions & 4 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ local update_floating_windows = function()
floating_windows = valid_windows
end

-- clean up neotree buffers created by :mksession
local cleaned_up = false
local clean_neotree_buffers = function()
if cleaned_up then
---Clean up invalid neotree buffers (e.g after a session restore)
---@param force boolean if true, force cleanup. Otherwise only cleanup once
M.clean_invalid_neotree_buffers = function(force)
if cleaned_up and not force then
return
end

Expand Down Expand Up @@ -839,7 +840,7 @@ create_window = function(state)
tabnr = state.tabnr,
}
events.fire_event(events.NEO_TREE_WINDOW_BEFORE_OPEN, event_args)
clean_neotree_buffers()
M.clean_invalid_neotree_buffers(false)

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