-
-
Notifications
You must be signed in to change notification settings - Fork 635
feat: restore buffers after loading a session #3335
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,41 @@ function M.global() | |
| end, | ||
| }) | ||
|
|
||
| vim.api.nvim_create_autocmd("SessionLoadPost", { | ||
| group = augroup_id, | ||
| callback = function() | ||
| local api = require("nvim-tree.api").tree | ||
|
|
||
| ---@type table<integer,boolean> | ||
| local tabs = {} | ||
|
|
||
| for _, tab in ipairs(vim.api.nvim_list_tabpages()) do | ||
| for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do | ||
| local buf = vim.api.nvim_win_get_buf(win) | ||
| if api.is_tree_buf(buf) then | ||
| tabs[tab] = true | ||
| end | ||
| end | ||
| end | ||
|
|
||
| vim.schedule(function() | ||
| api.close_in_all_tabs() | ||
|
|
||
| for tab, _ in pairs(tabs) do | ||
| if vim.api.nvim_tabpage_is_valid(tab) then | ||
| local win = vim.api.nvim_tabpage_get_win(tab) | ||
|
|
||
| if vim.api.nvim_win_is_valid(win) then | ||
| vim.api.nvim_win_call(win, function() | ||
| api.open() | ||
| end) | ||
|
Comment on lines
+44
to
+47
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an edge case with this approach: if |
||
| end | ||
| end | ||
| end | ||
| end) | ||
| end, | ||
| }) | ||
|
|
||
| if config.g.tab.sync.open then | ||
| vim.api.nvim_create_autocmd("TabEnter", { | ||
| group = augroup_id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with this location since it was the standard, but it might a good idea have this as an eager autocmd. Otherwise, any means of "lazy loading" may end up calling
setuptoo late (sessions could be loaded relatively early, as in, part of the initilization withnvim -S Session.vim).