patch 9.1.1679: unclear what key causes CmdlineLeave autocommand

Problem:  unclear what key causes CmdlineLeave autocommand
Solution: Set |v:char| to the key (Girish Palya).

related: #17806
closes: #18063

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Girish Palya
2025-08-23 18:08:27 +02:00
committed by Christian Brabandt
parent 53466887f7
commit ba9551d131
7 changed files with 41 additions and 4 deletions

View File

@ -1980,6 +1980,9 @@ getcmdline_int(
#endif
|| c == Ctrl_C))
{
#ifdef FEAT_EVAL
set_vim_var_char(c); // Set v:char
#endif
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
event_cmdlineleavepre_triggered = TRUE;
#if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
@ -2646,7 +2649,12 @@ cmdline_changed:
returncmd:
// Trigger CmdlineLeavePre autocommands if not already triggered.
if (!event_cmdlineleavepre_triggered)
{
#ifdef FEAT_EVAL
set_vim_var_char(c); // Set v:char
#endif
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
}
#ifdef FEAT_RIGHTLEFT
cmdmsg_rl = FALSE;
@ -2704,6 +2712,9 @@ returncmd:
need_wait_return = FALSE;
// Trigger CmdlineLeave autocommands.
#ifdef FEAT_EVAL
set_vim_var_char(c); // Set v:char
#endif
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE);
State = save_State;

View File

@ -25,5 +25,5 @@ int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp);
void wildmenu_cleanup(cmdline_info_T *cclp);
void f_getcompletion(typval_T *argvars, typval_T *rettv);
void f_getcompletiontype(typval_T *argvars, typval_T *rettv);
void f_cmdcomplete_info(typval_T *argvars, typval_T *rettv);
void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv);
/* vim: set ft=c : */

View File

@ -4918,4 +4918,23 @@ func Test_long_line_noselect()
call StopVimInTerminal(buf)
endfunc
func Test_CmdlineLeave_vchar_keys()
func OnLeave()
let g:leave_key = v:char
endfunction
new
for event in ["CmdlineLeavePre", "CmdlineLeave"]
exec "autocmd" event "* :call OnLeave()"
for key in ["\<C-C>", "\<Esc>", "\<CR>"]
call feedkeys($":echo{key}", 'tx')
call assert_equal(key, g:leave_key)
endfor
exec "autocmd!" event
endfor
bwipe!
delfunc OnLeave
unlet g:leave_key
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -724,6 +724,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1679,
/**/
1678,
/**/