fix: guard original_bufnr validity on borrowed restore

If the user deletes the original empty buffer (:bw!) between
hide and restore, nvim_win_set_buf would error. Now falls back
to closing the window if the original buffer is invalid.
This commit is contained in:
QQ 2026-06-17 16:36:24 +08:00
parent 25ea356161
commit 628f8250f8
1 changed files with 6 additions and 2 deletions

View File

@ -121,11 +121,15 @@ function M.open(cmd)
vim.notify('QQdock: hide [' .. name .. ']', vim.log.levels.INFO)
end
if term.borrowed then
-- 占了主窗口 → 换回原始空 buffer
-- 占了主窗口 → 换回原始空 buffer如果还在的话否则关窗
if term.original_bufnr and vim.api.nvim_buf_is_valid(term.original_bufnr) then
vim.api.nvim_win_set_buf(term.winid, term.original_bufnr)
else
vim.api.nvim_win_close(term.winid, true)
end
else
vim.api.nvim_win_close(term.winid, true)
end
term.winid = nil
term.borrowed = nil
return