fix: detect buffer mismatch on toggle (e.g. :e opened file over terminal)
When terminal occupies main window and user directly opens a file (:e somefile) in that window, the window's buffer no longer matches term.bufnr. Previously this caused the hide path to incorrectly swap back original_bufnr, wiping the user's file. Now we detect mismatch, clear winid/borrowed, and re-evaluate use_main — which will correctly fall through to a split when a real file is present.
This commit is contained in:
parent
81d623c5c0
commit
718ce9036f
|
|
@ -110,18 +110,24 @@ function M.open(cmd)
|
||||||
|
|
||||||
-- 已打开 → 关闭/隐藏,终端进程继续
|
-- 已打开 → 关闭/隐藏,终端进程继续
|
||||||
if term and term.winid and vim.api.nvim_win_is_valid(term.winid) then
|
if term and term.winid and vim.api.nvim_win_is_valid(term.winid) then
|
||||||
if config.debug then
|
-- 窗口 buffer 已被替换(用户直接 :e 打开了文件)→ 当作已隐藏
|
||||||
vim.notify('QQdock: hide [' .. name .. ']', vim.log.levels.INFO)
|
if vim.api.nvim_win_get_buf(term.winid) ~= term.bufnr then
|
||||||
end
|
term.winid = nil
|
||||||
if term.borrowed then
|
term.borrowed = nil
|
||||||
-- 占了主窗口 → 换回原始空 buffer
|
|
||||||
vim.api.nvim_win_set_buf(term.winid, term.original_bufnr)
|
|
||||||
else
|
else
|
||||||
vim.api.nvim_win_close(term.winid, true)
|
if config.debug then
|
||||||
|
vim.notify('QQdock: hide [' .. name .. ']', vim.log.levels.INFO)
|
||||||
|
end
|
||||||
|
if term.borrowed then
|
||||||
|
-- 占了主窗口 → 换回原始空 buffer
|
||||||
|
vim.api.nvim_win_set_buf(term.winid, term.original_bufnr)
|
||||||
|
else
|
||||||
|
vim.api.nvim_win_close(term.winid, true)
|
||||||
|
end
|
||||||
|
term.winid = nil
|
||||||
|
term.borrowed = nil
|
||||||
|
return
|
||||||
end
|
end
|
||||||
term.winid = nil
|
|
||||||
term.borrowed = nil
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 需要打开 → 基于当前窗口计算布局
|
-- 需要打开 → 基于当前窗口计算布局
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue