commit 236947ab20b82417eb4f3f69dd46740f299b7fdf
parent d81d8d454a151c60f4281c904e387661712b7984
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 30 Jun 2022 20:02:13 +0800
vim-patch:8.1.1274: after :unmenu can still execute the menu with :emenu
Problem: After :unmenu can still execute the menu with :emenu.
Solution: Do not execute a menu that was disabled for the specified mode.
https://github.com/vim/vim/commit/ce79353ace9e21238f13655089363cd23cbb6b32
Diffstat:
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
@@ -1501,7 +1501,7 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx)
}
assert(idx != MENU_INDEX_INVALID);
- if (menu->strings[idx] != NULL) {
+ if (menu->strings[idx] != NULL && (menu->modes & (1 << idx))) {
// When executing a script or function execute the commands right now.
// Also for the window toolbar
// Otherwise put them in the typeahead buffer.
diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim
@@ -60,8 +60,23 @@ func Test_menu_commands()
emenu c Test.FooBar
call assert_equal('cmdline', g:did_menu)
- aunmenu Test.FooBar
+ nunmenu Test.FooBar
+ call assert_fails('emenu n Test.FooBar', 'E335: Menu not defined for Normal mode')
+ vunmenu Test.FooBar
+ call assert_fails('emenu v Test.FooBar', 'E335: Menu not defined for Visual mode')
+ vmenu 2 Test.FooBar :let g:did_menu = 'visual'<CR>
+ sunmenu Test.FooBar
+ call assert_fails('emenu s Test.FooBar', 'E335: Menu not defined for Select mode')
+ ounmenu Test.FooBar
+ call assert_fails('emenu o Test.FooBar', 'E335: Menu not defined for Op-pending mode')
+ iunmenu Test.FooBar
+ call assert_fails('emenu i Test.FooBar', 'E335: Menu not defined for Insert mode')
+ cunmenu Test.FooBar
+ call assert_fails('emenu c Test.FooBar', 'E335: Menu not defined for Cmdline mode')
tlunmenu Test.FooBar
+ call assert_fails('emenu t Test.FooBar', 'E335: Menu not defined for Terminal mode')
+
+ aunmenu Test.FooBar
call assert_fails('emenu n Test.FooBar', 'E334:')
nmenu 2 Test.FooBar.Child :let g:did_menu = 'foobar'<CR>