fix: open the file in nvim when the terminal plugin wipes its buffer
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
10c2362482
commit
98f597ffae
1 file changed
+8
-2
@@ -169,7 +169,9 @@ func (m *Model) handleEditDone(msg editDoneMsg) tea.Cmd {
|
|||||||
// that terminal's own process (the nvim plugin, or :terminal lazysecrets),
|
// 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
|
// 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
|
// 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 = ...
|
const nvimLua = `local path, line, pid = ...
|
||||||
local function open()
|
local function open()
|
||||||
local ok, err = pcall(vim.cmd, "edit " .. vim.fn.fnameescape(path))
|
local ok, err = pcall(vim.cmd, "edit " .. vim.fn.fnameescape(path))
|
||||||
@@ -178,7 +180,11 @@ local function open()
|
|||||||
end
|
end
|
||||||
for _, b in ipairs(vim.api.nvim_list_bufs()) do
|
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
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user