fix(cmdline): redraw cmdline after empty message (#38485)

Problem: Cmdline is not redrawn after an empty message clears it.
Remembered last drawn cursor position may be outdated but
equal to the current cmdline content with UI2.
Solution: Ensure cmdline is redrawn after an empty message clears it.
Compare wanted cursor position with actual cursor position.
This commit is contained in:
luukvbaal
2026-03-31 14:16:55 +02:00
committed by GitHub
parent 1bcf2d7f90
commit 1685ced335
3 changed files with 15 additions and 6 deletions

View File

@@ -121,23 +121,22 @@ function M.cmdline_special_char(c, shift)
end)
end
local curpos = { 0, 0 } -- Last drawn cursor position.
--- Set the cmdline cursor position.
---
---@param pos integer
--@param level integer
function M.cmdline_pos(pos)
local curpos = api.nvim_win_get_cursor(ui.wins.cmd)
pos = #fn.strtrans(cmdbuff:sub(1, pos))
if curpos[1] ~= M.erow + 1 or curpos[2] ~= promptlen + pos then
curpos[1], curpos[2] = M.erow + 1, promptlen + pos
-- Add matchparen highlighting to non-prompt part of cmdline.
if pos > 0 and fn.exists('#matchparen#CursorMoved') == 1 then
api.nvim_win_set_cursor(ui.wins.cmd, { curpos[1], curpos[2] - 1 })
api.nvim_win_set_cursor(ui.wins.cmd, { M.erow + 1, promptlen + pos - 1 })
vim._with({ win = ui.wins.cmd, wo = { eventignorewin = '' } }, function()
api.nvim_exec_autocmds('CursorMoved', {})
end)
end
api.nvim_win_set_cursor(ui.wins.cmd, curpos)
api.nvim_win_set_cursor(ui.wins.cmd, { M.erow + 1, promptlen + pos })
end
end
@@ -176,7 +175,7 @@ function M.cmdline_hide(level, abort)
end
end)
M.prompt, M.level, curpos[1], curpos[2] = false, 0, 0, 0
M.prompt, M.level = false, 0
win_config(ui.wins.cmd, true, ui.cmdheight)
end