vim-patch:9.0.0713: <amatch> of MenuPopup event is expanded like a file name (#20572)

Problem:    <amatch> of MenuPopup event is expanded like a file name.
Solution:   Do not expand <amatch> for MenuPopup. (closes vim/vim#11328)
c601d988b6
This commit is contained in:
zeertzjq 2022-10-10 21:26:18 +08:00 committed by GitHub
parent d4e749f1b2
commit 81058119df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 8 deletions

View File

@ -1743,17 +1743,18 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
sfname = xstrdup(fname); sfname = xstrdup(fname);
// Don't try expanding the following events. // Don't try expanding the following events.
if (event == EVENT_CMDLINECHANGED || event == EVENT_CMDLINEENTER if (event == EVENT_CMDLINECHANGED || event == EVENT_CMDLINEENTER
|| event == EVENT_CMDLINELEAVE || event == EVENT_CMDWINENTER || event == EVENT_CMDLINELEAVE || event == EVENT_CMDUNDEFINED
|| event == EVENT_CMDWINLEAVE || event == EVENT_CMDUNDEFINED || event == EVENT_CMDWINENTER || event == EVENT_CMDWINLEAVE
|| event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE || event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
|| event == EVENT_DIRCHANGED || event == EVENT_DIRCHANGEDPRE || event == EVENT_DIRCHANGED || event == EVENT_DIRCHANGEDPRE
|| event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED || event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED
|| event == EVENT_MODECHANGED || event == EVENT_OPTIONSET || event == EVENT_MENUPOPUP || event == EVENT_MODECHANGED
|| event == EVENT_QUICKFIXCMDPOST || event == EVENT_QUICKFIXCMDPRE || event == EVENT_OPTIONSET || event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_REMOTEREPLY || event == EVENT_SPELLFILEMISSING || event == EVENT_QUICKFIXCMDPRE || event == EVENT_REMOTEREPLY
|| event == EVENT_SYNTAX || event == EVENT_SIGNAL || event == EVENT_SIGNAL || event == EVENT_SPELLFILEMISSING
|| event == EVENT_TABCLOSED || event == EVENT_USER || event == EVENT_SYNTAX || event == EVENT_TABCLOSED
|| event == EVENT_WINCLOSED || event == EVENT_WINSCROLLED) { || event == EVENT_USER || event == EVENT_WINCLOSED
|| event == EVENT_WINSCROLLED) {
fname = xstrdup(fname); fname = xstrdup(fname);
} else { } else {
fname = FullName_save(fname, false); fname = FullName_save(fname, false);

View File

@ -481,6 +481,35 @@ func Test_popup_menu()
unmenu PopUp unmenu PopUp
endfunc endfunc
" Test for MenuPopup autocommand
func Test_autocmd_MenuPopup()
CheckNotGui
set mouse=a
set mousemodel=popup
aunmenu *
autocmd MenuPopup * exe printf(
\ 'anoremenu PopUp.Foo <Cmd>let g:res = ["%s", "%s"]<CR>',
\ expand('<afile>'), expand('<amatch>'))
call feedkeys("\<RightMouse>\<Down>\<CR>", 'tnix')
call assert_equal(['n', 'n'], g:res)
call feedkeys("v\<RightMouse>\<Down>\<CR>\<Esc>", 'tnix')
call assert_equal(['v', 'v'], g:res)
call feedkeys("gh\<RightMouse>\<Down>\<CR>\<Esc>", 'tnix')
call assert_equal(['s', 's'], g:res)
call feedkeys("i\<RightMouse>\<Down>\<CR>\<Esc>", 'tnix')
call assert_equal(['i', 'i'], g:res)
autocmd! MenuPopup
aunmenu PopUp.Foo
unlet g:res
set mouse& mousemodel&
endfunc
" Test for listing the menus using the :menu command " Test for listing the menus using the :menu command
func Test_show_menus() func Test_show_menus()
" In the GUI, tear-off menu items are present in the output below " In the GUI, tear-off menu items are present in the output below