Skip to content

Commit 12a7d39

Browse files
fix: prevent double-edit of current buffer after load
1 parent 8c553c7 commit 12a7d39

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lua/resession/init.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,16 @@ M.load = function(name, opts)
444444
local bufnr = vim.fn.bufadd(buf.name)
445445
if buf.loaded then
446446
vim.fn.bufload(bufnr)
447+
vim.b[bufnr]._resession_need_edit = true
447448
vim.api.nvim_create_autocmd("BufEnter", {
448449
desc = "Resession: complete setup of restored buffer",
449450
callback = function(args)
450451
pcall(vim.api.nvim_win_set_cursor, 0, buf.last_pos)
451-
-- We have to schedule :edit otherwise it recurses
452-
vim.schedule(function()
453-
if vim.api.nvim_get_current_buf() == args.buf then
454-
-- This triggers the autocmds that set filetype, syntax highlighting, and checks the swapfile
455-
vim.cmd.edit({ mods = { emsg_silent = true } })
456-
end
457-
end)
452+
-- This triggers the autocmds that set filetype, syntax highlighting, and checks the swapfile
453+
if vim.b._resession_need_edit then
454+
vim.b._resession_need_edit = nil
455+
vim.cmd.edit({ mods = { emsg_silent = true } })
456+
end
458457
end,
459458
buffer = bufnr,
460459
once = true,
@@ -524,6 +523,7 @@ M.load = function(name, opts)
524523
dispatch("post_load", name, opts)
525524

526525
-- In case the current buffer has a swapfile, make sure we trigger all the necessary autocmds
526+
vim.b._resession_need_edit = nil
527527
vim.cmd.edit({ mods = { emsg_silent = true } })
528528
end
529529

0 commit comments

Comments
 (0)