From b51eba927324e12271dcb6c4db25e430c4aa6eb9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 8 Sep 2025 11:42:27 +0800 Subject: [PATCH] vim-patch:9.1.1738: cmdline-autocompletion breaks history navigation Problem: cmdline-autocompletion breaks history navigation (ddad431) Solution: Support history navigation in cmdline autocompletion (Girish Palya) Up/Down arrows support history navigation when using wildtrigger() fixes: vim/vim#18207 closes: vim/vim#18219 https://github.com/vim/vim/commit/708ab7f5fbef95c43a3eb6c0a2ad4e02ad4c2f98 Co-authored-by: Girish Palya --- src/nvim/ex_getln.c | 8 ++++++++ test/old/testdir/test_cmdline.vim | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f17dcd5ae0..e93698be94 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -146,6 +146,7 @@ typedef struct { buf_T *b_im_ptr_buf; ///< buffer where b_im_ptr is valid int cmdline_type; bool event_cmdlineleavepre_triggered; + bool did_hist_navigate; } CommandLineState; typedef struct { @@ -1254,6 +1255,12 @@ static int command_line_execute(VimState *state, int key) CommandLineState *s = (CommandLineState *)state; s->c = key; + // Skip wildmenu during history navigation via Up/Down keys + if (s->c == K_WILD && s->did_hist_navigate) { + s->did_hist_navigate = false; + return 1; + } + if (s->c == K_EVENT || s->c == K_COMMAND || s->c == K_LUA) { if (s->c == K_EVENT) { state_handle_k_event(); @@ -2227,6 +2234,7 @@ static int command_line_handle_key(CommandLineState *s) } else { switch (command_line_browse_history(s)) { case CMDLINE_CHANGED: + s->did_hist_navigate = true; return command_line_changed(s); case GOTO_NORMAL_MODE: return 0; diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 41c9eb9398..fa230f7034 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -4986,4 +4986,28 @@ func Test_CmdlineLeave_vchar_keys() unlet g:leave_key endfunc +" Skip wildmenu during history navigation via Up/Down keys +func Test_skip_wildtrigger_hist_navigation() + call Ntest_override("char_avail", 1) + cnoremap =wildtrigger()[-1] + set wildmenu + + call feedkeys(":ech\\\\"\", "tx") + call assert_match('echo*', g:Sline) + call assert_equal('"echo', @:) + + call feedkeys(":echom \"foo\"", "tx") + call feedkeys(":echom \"foobar\"", "tx") + call feedkeys(":ech\\\\\"\", "tx") + call assert_equal('"echom "foobar"', @:) + call feedkeys(":ech\\\\\\\"\", "tx") + call assert_equal('"echom "foo"', @:) + call feedkeys(":ech\\\\\\\\"\", "tx") + call assert_equal('"echom "foobar"', @:) + + call Ntest_override("char_avail", 0) + set wildmenu& + cunmap +endfunc + " vim: shiftwidth=2 sts=2 expandtab