From 0763a85f43fb6a22cf3db758b8dec3181c4035ff Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 19 Sep 2025 09:48:17 +0800 Subject: [PATCH] vim-patch:9.1.1771: complete: some redraw issues with 'autocomplete' Problem: complete: some redraw issues with 'autocomplete' Solution: Fix the issues (Girish Palya) This commit contains the following changes: * Fix that wildtrigger() might leave opened popupmenu around vim/vim#18298 * Remove blinking message on the command line when a menu item from a loaded buffer is selected during 'autocomplete' * Add a test for PR vim/vim#18265 to demonstrate why the PR is required for correct 'autocomplete' behavior fixes: vim/vim#18298 closes: vim/vim#18328 https://github.com/vim/vim/commit/ee9a2f0512e8b732e3c6a000974aa7e3f6028989 Co-authored-by: Girish Palya --- src/nvim/ex_getln.c | 9 ++++---- src/nvim/insexpand.c | 14 +++++++----- test/functional/legacy/cmdline_spec.lua | 29 +++++++++++++++++++++++++ test/old/testdir/test_cmdline.vim | 19 ++++++++++++++++ test/old/testdir/test_ins_complete.vim | 9 +++++++- 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d345990ac6..c226eef136 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1241,10 +1241,11 @@ static int command_line_wildchar_complete(CommandLineState *s) return (res == OK) ? CMDLINE_CHANGED : CMDLINE_NOT_CHANGED; } -static void command_line_end_wildmenu(CommandLineState *s) +static void command_line_end_wildmenu(CommandLineState *s, bool key_is_wc) { if (cmdline_pum_active()) { - s->skip_pum_redraw = (s->skip_pum_redraw + s->skip_pum_redraw = (s->skip_pum_redraw && !key_is_wc + && !ascii_iswhite(s->c) && (vim_isprintc(s->c) || s->c == K_BS || s->c == Ctrl_H || s->c == K_DEL || s->c == K_KDEL || s->c == Ctrl_W || s->c == Ctrl_U)); @@ -1301,7 +1302,7 @@ static int command_line_execute(VimState *state, int key) nextwild(&s->xpc, WILD_PUM_WANT, 0, s->firstc != '@'); if (pum_want.finish) { nextwild(&s->xpc, WILD_APPLY, WILD_NO_BEEP, s->firstc != '@'); - command_line_end_wildmenu(s); + command_line_end_wildmenu(s, false); } } pum_want.active = false; @@ -1408,7 +1409,7 @@ static int command_line_execute(VimState *state, int key) // free expanded names when finished walking through matches if (end_wildmenu) { - command_line_end_wildmenu(s); + command_line_end_wildmenu(s, key_is_wc); } if (p_wmnu) { diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 30a49dd833..8a14005028 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -5189,12 +5189,14 @@ static void ins_compl_show_filename(void) MB_PTR_ADV(s); } } - msg_hist_off = true; - vim_snprintf(IObuff, IOSIZE, "%s %s%s", lead, - s > compl_shown_match->cp_fname ? "<" : "", s); - msg(IObuff, 0); - msg_hist_off = false; - redraw_cmdline = false; // don't overwrite! + if (!compl_autocomplete) { + msg_hist_off = true; + vim_snprintf(IObuff, IOSIZE, "%s %s%s", lead, + s > compl_shown_match->cp_fname ? "<" : "", s); + msg(IObuff, 0); + msg_hist_off = false; + redraw_cmdline = false; // don't overwrite! + } } /// Find the appropriate completion item when 'complete' ('cpt') includes diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 44576ce7df..8ee80e5dca 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -627,6 +627,35 @@ describe('cmdline', function() feed('') end) + + -- oldtest: Test_update_screen_after_wildtrigger() + it('pum is dismissed after wildtrigger() and whitespace', function() + local screen = Screen.new(40, 10) + exec([[ + set wildmode=noselect:lastused,full wildmenu wildoptions=pum + autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif + ]]) + + feed(':term') + screen:expect([[ + | + {1:~ }|*7 + {4: terminal }{1: }| + :term^ | + ]]) + feed(' ') + screen:expect([[ + | + {1:~ }|*8 + :term ^ | + ]]) + feed('foo') + screen:expect([[ + | + {1:~ }|*8 + :term foo^ | + ]]) + end) end) describe('cmdwin', function() diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 69923129f5..8950690633 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -5053,4 +5053,23 @@ func Test_skip_wildtrigger_hist_navigation() cunmap endfunc +" Issue 18298: wildmenu should be dismissed after wildtrigger and whitespace +func Test_update_screen_after_wildtrigger() + CheckScreendump + let lines =<< trim [SCRIPT] + call test_override("char_avail", 1) + set wildmode=noselect:lastused,full wildmenu wildoptions=pum + autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif + [SCRIPT] + call writefile(lines, 'XTest_wildtrigger', 'D') + let buf = RunVimInTerminal('-S XTest_wildtrigger', {'rows': 10}) + + call term_sendkeys(buf, ":term foo") + call TermWait(buf, 50) + call VerifyScreenDump(buf, 'Test_update_screen_wildtrigger_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index cdf83d62d0..c0fa3ac260 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -5359,7 +5359,7 @@ func Test_autocomplete_trigger() call feedkeys("Sazx\\\\0", 'tx!') call assert_equal(['and', 'afoo'], b:matches->mapnew('v:val.word')) - " Test 6: should clear the selected item + " Test 6: should clear the selected item (PR #18265) %d call setline(1, ["foobarfoo", "foobar", "foobarbaz"]) call feedkeys("Gofo\\\\\0", 'tx!') @@ -5374,6 +5374,13 @@ func Test_autocomplete_trigger() call assert_equal(0, b:selected) call assert_equal('foobarbaz', getline(4)) + " Test 7: Remove selection when menu contents change (PR #18265) + %d + call setline(1, ["foobar", "fodxyz", "fodabc"]) + call feedkeys("Gofoo\\\\\d\\\0", 'tx!') + call assert_equal(['fodabc', 'fodxyz'], b:matches->mapnew('v:val.word')) + call assert_equal(-1, b:selected) + bw! call Ntest_override("char_avail", 0) delfunc NonKeywordComplete