aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/menu.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-06-30 15:30:54 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-01 10:17:39 +0800
commit610cf9f95032bd219cb5695d169fe2cd698ec307 (patch)
treee294c5bcae1401e0ba3fa37ed6c60417d47f960f /src/nvim/menu.c
parentcf8df141f3c7e706c86aadba404ae8ad54d5c795 (diff)
downloadrneovim-610cf9f95032bd219cb5695d169fe2cd698ec307.tar.gz
rneovim-610cf9f95032bd219cb5695d169fe2cd698ec307.tar.bz2
rneovim-610cf9f95032bd219cb5695d169fe2cd698ec307.zip
vim-patch:8.0.1570: can't use :popup for a menu in the terminal
Problem: Can't use :popup for a menu in the terminal. (Wei Zhang) Solution: Make :popup work in the terminal. Also fix that entries were included that don't work in the current state. https://github.com/vim/vim/commit/29a2c08d792e4458a0af8371f5341394829fce29
Diffstat (limited to 'src/nvim/menu.c')
-rw-r--r--src/nvim/menu.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 5e4dc12e40..73472ff1c4 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -1382,6 +1382,16 @@ static int get_menu_mode(void)
return MENU_INDEX_INVALID;
}
+int get_menu_mode_flag(void)
+{
+ int mode = get_menu_mode();
+
+ if (mode == MENU_INDEX_INVALID) {
+ return 0;
+ }
+ return 1 << mode;
+}
+
/// Display the Special "PopUp" menu as a pop-up at the current mouse
/// position. The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode,
/// etc.
@@ -1545,6 +1555,52 @@ void ex_emenu(exarg_T *eap)
execute_menu(eap, menu);
}
+/// Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy.
+vimmenu_T *menu_find(const char *path_name)
+{
+ vimmenu_T *menu = *get_root_menu(path_name);
+ char *saved_name = xstrdup(path_name);
+ char *name = saved_name;
+ while (*name) {
+ // find the end of one dot-separated name and put a NUL at the dot
+ char *p = menu_name_skip(name);
+
+ while (menu != NULL) {
+ if (menu_name_equal(name, menu)) {
+ if (menu->children == NULL) {
+ // found a menu item instead of a sub-menu
+ if (*p == NUL) {
+ emsg(_("E336: Menu path must lead to a sub-menu"));
+ } else {
+ emsg(_(e_notsubmenu));
+ }
+ menu = NULL;
+ goto theend;
+ }
+ if (*p == NUL) { // found a full match
+ goto theend;
+ }
+ break;
+ }
+ menu = menu->next;
+ }
+ if (menu == NULL) { // didn't find it
+ break;
+ }
+
+ // Found a match, search the sub-menu.
+ menu = menu->children;
+ name = p;
+ }
+
+ if (menu == NULL) {
+ emsg(_("E337: Menu not found - check menu names"));
+ }
+theend:
+ xfree(saved_name);
+ return menu;
+}
+
/*
* Translation of menu names. Just a simple lookup table.
*/