summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/_extui/cmdline.lua
diff options
context:
space:
mode:
authorluukvbaal <luukvbaal@gmail.com>2025-06-04 19:59:36 +0200
committerGitHub <noreply@github.com>2025-06-04 19:59:36 +0200
commit5e4700152b79e090d880d2734e0eaec726f4b8a7 (patch)
treeb09f9973e0e1641a0392a55b7133d4b9b640ab7a /runtime/lua/vim/_extui/cmdline.lua
parent03832842d537f67c6a21d7710465f0206eccd7b0 (diff)
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).
Diffstat (limited to 'runtime/lua/vim/_extui/cmdline.lua')
-rw-r--r--runtime/lua/vim/_extui/cmdline.lua22
1 files changed, 11 insertions, 11 deletions
diff --git a/runtime/lua/vim/_extui/cmdline.lua b/runtime/lua/vim/_extui/cmdline.lua
index 0f31d63e59..eecd28cde2 100644
--- a/runtime/lua/vim/_extui/cmdline.lua
+++ b/runtime/lua/vim/_extui/cmdline.lua
@@ -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.