]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1738: cmdline-autocompletion breaks history navigation v9.1.1738
authorGirish Palya <girishji@gmail.com>
Sat, 6 Sep 2025 17:47:45 +0000 (19:47 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 6 Sep 2025 17:54:59 +0000 (19:54 +0200)
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: #18207
closes: #18219

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/builtin.txt
src/ex_getln.c
src/testdir/test_cmdline.vim
src/version.c

index 40e6d93eb5f8a7d07a4ce6f555c2bef3f1a34676..1b15246da11f2b6e912660a6bfa9cb9c6d2516bc 100644 (file)
@@ -1,4 +1,4 @@
-*builtin.txt*  For Vim version 9.1.  Last change: 2025 Sep 02
+*builtin.txt*  For Vim version 9.1.  Last change: 2025 Sep 06
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -12416,18 +12416,19 @@ wildtrigger()                                         *wildtrigger()*
                produce a beep when no matches are found and generally
                operates more quietly.  This makes it suitable for triggering
                completion automatically, such as from an |:autocmd|.
+
                                                *cmdline-autocompletion*
-               Example: To make the completion menu pop up automatically as
-               you type on the command line, use: >
+               Example: To make the completion menu pop up automatically
+               while typing on the command line: >
                        autocmd CmdlineChanged [:/\?] call wildtrigger()
                        set wildmode=noselect:lastused,full wildoptions=pum
 <
-               To retain normal history navigation (up/down keys): >
-                       cnoremap <Up>   <C-U><Up>
-                       cnoremap <Down> <C-U><Down>
+               To retain normal history navigation with the up/down keys: >
+                       cnoremap <expr> <Up>   wildmenumode() ? "\<C-E>\<Up>"   : "\<Up>"
+                       cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"
 <
-               To set an option specifically when performing a search, e.g.
-               to set 'pumheight': >
+               To apply an option only during a search, for example to set
+               'pumheight': >
                        autocmd CmdlineEnter [/\?] set pumheight=8
                        autocmd CmdlineLeave [/\?] set pumheight&
 <
index a7f957eab48e2ad817da7dcf6432ce4ffd446323..07c15ef2a86564f029fe93455aca86d08e72bf58 100644 (file)
@@ -1681,6 +1681,7 @@ getcmdline_int(
     int                wild_type = 0;
     int                event_cmdlineleavepre_triggered = FALSE;
     char_u     *prev_cmdbuff = NULL;
+    int                did_hist_navigate = FALSE;
 
     // one recursion level deeper
     ++depth;
@@ -1891,6 +1892,13 @@ getcmdline_int(
            c = safe_vgetc();
        } while (c == K_IGNORE || c == K_NOP);
 
+       // Skip wildmenu during history navigation via Up/Down keys
+       if (c == K_WILD && did_hist_navigate)
+       {
+           did_hist_navigate = FALSE;
+           continue;
+       }
+
        if (c == K_COMMAND || c == K_SCRIPT_COMMAND)
        {
            int     clen = ccline.cmdlen;
@@ -2489,7 +2497,10 @@ getcmdline_int(
                    res = cmdline_browse_history(c, firstc, &lookfor, &lookforlen, histype,
                            &hiscnt, &xpc);
                    if (res == CMDLINE_CHANGED)
+                   {
+                       did_hist_navigate = TRUE;
                        goto cmdline_changed;
+                   }
                    else if (res == GOTO_NORMAL_MODE)
                        goto returncmd;
                }
index 09dfa3e93bd64ca720637494abc93c1d81bab775..4e6b5351597bc247c7aa500dd57de0b216232089 100644 (file)
@@ -5039,4 +5039,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 test_override("char_avail", 1)
+  cnoremap <F8> <C-R>=wildtrigger()[-1]<CR>
+  set wildmenu
+
+  call feedkeys(":ech\<F8>\<F4>\<C-B>\"\<CR>", "tx")
+  call assert_match('echo*', g:Sline)
+  call assert_equal('"echo', @:)
+
+  call feedkeys(":echom \"foo\"", "tx")
+  call feedkeys(":echom \"foobar\"", "tx")
+  call feedkeys(":ech\<F8>\<C-E>\<UP>\<C-B>\"\<CR>", "tx")
+  call assert_equal('"echom "foobar"', @:)
+  call feedkeys(":ech\<F8>\<C-E>\<UP>\<UP>\<UP>\<C-B>\"\<CR>", "tx")
+  call assert_equal('"echom "foo"', @:)
+  call feedkeys(":ech\<F8>\<C-E>\<UP>\<UP>\<UP>\<Down>\<C-B>\"\<CR>", "tx")
+  call assert_equal('"echom "foobar"', @:)
+
+  call test_override("char_avail", 0)
+  set wildmenu&
+  cunmap <F8>
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 596cd17dd81cc0407ebb95b5b3e62c68f625dc97..06b7a5ba752d3f5cfb86635bbc030dcc00f6e1c1 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1738,
 /**/
     1737,
 /**/