diff --git a/src/nvim/menu.c b/src/nvim/menu.c index d3c22eee1f..d4fd0a067c 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1471,18 +1471,18 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx) int idx = mode_idx; if (idx < 0) { - // Use the Insert mode entry when returning to Insert mode. - if (((State & MODE_INSERT) || restart_edit) && current_sctx.sc_sid == 0) { - idx = MENU_INDEX_INSERT; + if (State & MODE_TERMINAL) { + idx = MENU_INDEX_TERMINAL; } else if (State & MODE_CMDLINE) { idx = MENU_INDEX_CMDLINE; - } else if (State & MODE_TERMINAL) { - idx = MENU_INDEX_TERMINAL; } else if (get_real_state() & MODE_VISUAL) { // Detect real visual mode -- if we are really in visual mode we // don't need to do any guesswork to figure out what the selection // is. Just execute the visual binding for the menu. idx = MENU_INDEX_VISUAL; + } else if (((State & MODE_INSERT) || restart_edit) && current_sctx.sc_sid == 0) { + // Use the Insert mode entry when returning to Insert mode. + idx = MENU_INDEX_INSERT; } else if (eap != NULL && eap->addr_count) { pos_T tpos; diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 4cade5e25e..72f686c839 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -57,6 +57,17 @@ describe(':emenu', function() -- Assert that Edit.Paste pasted @" into the commandline. eq('thiscmdmode', eval('getcmdline()')) end) + + it('popup menu in visual mode via from insert mode #19473', function() + n.exec([[ + aunmenu * + source $VIMRUNTIME/menu.vim + ]]) + feed('itextV') + command('emenu PopUp.Cut') + eq('', fn.getline(1)) + eq('', n.api.nvim_get_vvar('errmsg')) + end) end) local test_menus_cmd = [=[