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

708ab7f5fb

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-09-08 11:42:27 +08:00
parent a7b8102f20
commit b51eba9273
2 changed files with 32 additions and 0 deletions

View File

@@ -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;

View File

@@ -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 <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 Ntest_override("char_avail", 0)
set wildmenu&
cunmap <F8>
endfunc
" vim: shiftwidth=2 sts=2 expandtab