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,6 +110,11 @@ 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
|
||||||
|
-- 窗口 buffer 已被替换(用户直接 :e 打开了文件)→ 当作已隐藏
|
||||||
|
if vim.api.nvim_win_get_buf(term.winid) ~= term.bufnr then
|
||||||
|
term.winid = nil
|
||||||
|
term.borrowed = nil
|
||||||
|
else
|
||||||
if config.debug then
|
if config.debug then
|
||||||
vim.notify('QQdock: hide [' .. name .. ']', vim.log.levels.INFO)
|
vim.notify('QQdock: hide [' .. name .. ']', vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
|
|
@ -123,6 +128,7 @@ function M.open(cmd)
|
||||||
term.borrowed = nil
|
term.borrowed = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- 需要打开 → 基于当前窗口计算布局
|
-- 需要打开 → 基于当前窗口计算布局
|
||||||
local direction, size = get_layout()
|
local direction, size = get_layout()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue