From 677446c70f8c3f8c42e31ea20b9c99b44839d268 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Nov 2025 09:40:20 +0800 Subject: [PATCH] fix(cmdline): make sure pum is removed on leave (#36608) --- src/nvim/ex_getln.c | 3 +++ test/functional/legacy/cmdline_spec.lua | 26 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 3f1b1dfe62..25e08cd589 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -933,6 +933,9 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear // sure to still clean up to avoid memory corruption. if (cmdline_pum_active()) { cmdline_pum_remove(false); + } else { + // A previous cmdline_pum_remove() may have deferred redraw. + pum_check_clear(); } wildmenu_cleanup(&ccline); s->did_wild_list = false; diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 06d52955a7..a84642e9c5 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -549,7 +549,7 @@ describe('cmdline', function() ]]) feed(':TestCmd a') - screen:expect([[ + local s1 = [[ | {1:~ }|*3 {1:~ }{4: abc1 }{1: }| @@ -558,13 +558,14 @@ describe('cmdline', function() {1:~ }{4: abc4 }{1: }| {1:~ }{4: abc5 }{1: }| :TestCmd a^ | - ]]) + ]] + screen:expect(s1) -- Typing a character when pum is open does not close the pum window -- This is needed to prevent pum window from flickering during -- ':h cmdline-autocompletion'. feed('x') - screen:expect([[ + local s2 = [[ | {1:~ }|*3 {1:~ }{4: abc1 }{1: }| @@ -573,9 +574,10 @@ describe('cmdline', function() {1:~ }{4: abc4 }{1: }| {1:~ }{4: abc5 }{1: }| :TestCmd ax^ | - ]]) + ]] + screen:expect(s2) - -- pum window is closed when no completion candidates are available + -- pum is closed when no completion candidates are available feed('') screen:expect([[ | @@ -583,7 +585,19 @@ describe('cmdline', function() :TestCmd ax^ | ]]) - feed('') + feed('') + screen:expect(s1) + + feed('x') + screen:expect(s2) + + -- pum is closed when leaving cmdline mode + feed('') + screen:expect([[ + ^ | + {1:~ }|*8 + | + ]]) end) -- oldtest: Test_long_line_noselect()