From 98f597ffaee9e3670b69915dd33cc22fd74b1beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Einar=20Bergstr=C3=B8m?= Date: Sun, 11 Oct 2026 00:29:00 +0200 Subject: [PATCH] fix: open the file in nvim when the terminal plugin wipes its buffer Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/ui/app/edit.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/ui/app/edit.go b/internal/ui/app/edit.go index add1444..83be600 100644 --- a/internal/ui/app/edit.go +++ b/internal/ui/app/edit.go @@ -169,7 +169,9 @@ func (m *Model) handleEditDone(msg editDoneMsg) tea.Cmd { // that terminal's own process (the nvim plugin, or :terminal lazysecrets), // it waits for the terminal to close, so the file opens in the window // below rather than in one about to close. Otherwise (a shell in a -// terminal) it opens it in the previous window now. +// terminal) it opens it in the previous window now. The autocmd isn't +// the buffer's own: snacks wipes the buffer when the terminal closes, +// which would delete it before it runs. const nvimLua = `local path, line, pid = ... local function open() local ok, err = pcall(vim.cmd, "edit " .. vim.fn.fnameescape(path)) @@ -178,7 +180,11 @@ local function open() end for _, b in ipairs(vim.api.nvim_list_bufs()) do if vim.bo[b].buftype == "terminal" and vim.b[b].terminal_job_pid == pid then - vim.api.nvim_create_autocmd("TermClose", { buffer = b, once = true, callback = function() vim.defer_fn(open, 50) end }) + vim.api.nvim_create_autocmd("TermClose", { callback = function(ev) + if ev.buf ~= b then return end + vim.defer_fn(open, 50) + return true + end }) return end end