fix(extui): copy window config to new tabpage (#34308)

Problem:  When opening a new tabpage, extui windows are initialized with
          their default config. Window visiblity/dimensions on other
          tabpages may get out of sync with their buffer content.
Solution: Copy the config of the window to the new tabpage.
          No longer keep track of the various windows on each tabpage.
          Close windows on inactive tabpages instead (moving them could
          be more efficient but is currently not supported in the API).
This commit is contained in:
luukvbaal
2025-06-04 19:59:36 +02:00
committed by GitHub
parent 03832842d5
commit 5e4700152b
4 changed files with 50 additions and 51 deletions

View File

@@ -64,8 +64,8 @@ function M.cmdline_show(content, pos, firstc, prompt, indent, level, hl_id)
api.nvim_buf_set_extmark(ext.bufs.cmd, ext.ns, 0, 0, { hl_group = hl_id, end_col = promptlen })
end
local height = math.max(ext.cmdheight, api.nvim_win_text_height(ext.wins[ext.tab].cmd, {}).all)
win_config(ext.wins[ext.tab].cmd, false, height)
local height = math.max(ext.cmdheight, api.nvim_win_text_height(ext.wins.cmd, {}).all)
win_config(ext.wins.cmd, false, height)
M.cmdline_pos(pos)
-- Clear message cmdline state; should not be shown during, and reset after cmdline.
@@ -83,7 +83,7 @@ end
---@param shift boolean
--@param level integer
function M.cmdline_special_char(c, shift)
api.nvim_win_call(ext.wins[ext.tab].cmd, function()
api.nvim_win_call(ext.wins.cmd, function()
api.nvim_put({ c }, shift and '' or 'c', false, false)
end)
end
@@ -99,12 +99,11 @@ function M.cmdline_pos(pos)
curpos[1], curpos[2] = M.row + 1, promptlen + pos
-- Add matchparen highlighting to non-prompt part of cmdline.
if pos > 0 and fn.exists('#matchparen') then
api.nvim_win_set_cursor(ext.wins[ext.tab].cmd, { curpos[1], curpos[2] - 1 })
vim.wo[ext.wins[ext.tab].cmd].eventignorewin = ''
fn.win_execute(ext.wins[ext.tab].cmd, 'doautocmd CursorMoved')
vim.wo[ext.wins[ext.tab].cmd].eventignorewin = 'all'
vim._with({ win = ext.wins.cmd, wo = { eventignorewin = '' } }, function()
api.nvim_exec_autocmds('CursorMoved', {})
end)
end
api.nvim_win_set_cursor(ext.wins[ext.tab].cmd, curpos)
api.nvim_win_set_cursor(ext.wins.cmd, curpos)
end
end
@@ -117,7 +116,8 @@ function M.cmdline_hide(_, abort)
return -- No need to hide when still in cmdline_block.
end
fn.clearmatches(ext.wins[ext.tab].cmd) -- Clear matchparen highlights.
fn.clearmatches(ext.wins.cmd) -- Clear matchparen highlights.
api.nvim_win_set_cursor(ext.wins.cmd, { 1, 0 })
if abort then
-- Clear cmd buffer for aborted command (non-abort is left visible).
api.nvim_buf_set_lines(ext.bufs.cmd, 0, -1, false, {})
@@ -128,7 +128,7 @@ function M.cmdline_hide(_, abort)
-- loop iteration. E.g. when a non-choice confirm button is pressed.
if was_prompt and not M.prompt then
api.nvim_buf_set_lines(ext.bufs.cmd, 0, -1, false, {})
api.nvim_win_set_config(ext.wins[ext.tab].prompt, { hide = true })
api.nvim_win_set_config(ext.wins.prompt, { hide = true })
end
-- Messages emitted as a result of a typed command are treated specially:
-- remember if the cmdline was used this event loop iteration.
@@ -140,7 +140,7 @@ function M.cmdline_hide(_, abort)
clear(M.prompt)
M.prompt, M.level, curpos[1], curpos[2] = false, 0, 0, 0
win_config(ext.wins[ext.tab].cmd, true, ext.cmdheight)
win_config(ext.wins.cmd, true, ext.cmdheight)
end
--- Set multi-line cmdline buffer text.