backport: fix(ui2): clear empty cmdline after backspace (#41048)

Problem:
Cmdline area shows stale ":" after backspacing out of the command line.

Solution:
Clear the command line for empty commands. Note that `:<CR>` will now
clear the command line too.

(cherry picked from commit 1dbc766fa7)
This commit is contained in:
Nathan Zeng
2026-07-29 11:19:17 -07:00
committed by GitHub
parent f0f6681cea
commit 27e196c7d6
2 changed files with 18 additions and 2 deletions

View File

@@ -159,8 +159,8 @@ function M.cmdline_hide(level, abort)
fn.clearmatches(ui.wins.cmd) -- Clear matchparen highlights.
api.nvim_win_set_cursor(ui.wins.cmd, { 1, 0 })
if M.prompt or abort then
-- Clear cmd buffer prompt or aborted command (non-abort is left visible).
if M.prompt or abort or cmdbuff == '' then
-- Clear cmd buffer prompt or aborted/empty command (non-abort is left visible).
api.nvim_buf_set_lines(ui.bufs.cmd, 0, -1, false, {})
end

View File

@@ -275,6 +275,22 @@ describe('cmdline2', function()
{16::}%{15:s}{16:/.\{//}^ } |
]])
end)
it('is empty after backspace', function()
feed(':')
screen:expect([[
|
{1:~ }|*12
{16::}^ |
]])
feed('<BS>')
screen:expect([[
^ |
{1:~ }|*12
|
]])
end)
end)
describe('cmdline2', function()