diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/menu.c | 17 | ||||
-rw-r--r-- | src/nvim/testdir/test_menu.vim | 3 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 58e4e634c4..be13675b2a 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1892,9 +1892,22 @@ static char *menu_translate_tab_and_shift(char *arg_start) } /// Get the information about a menu item in mode 'which' -static void menuitem_getinfo(const vimmenu_T *menu, int modes, dict_T *dict) +static void menuitem_getinfo(const char *menu_name, const vimmenu_T *menu, int modes, dict_T *dict) FUNC_ATTR_NONNULL_ALL { + if (*menu_name == NUL) { + // Return all the top-level menus + list_T *const l = tv_list_alloc(kListLenMayKnow); + tv_dict_add_list(dict, S_LEN("submenus"), l); + // get all the children. Skip PopUp[nvoci]. + for (const vimmenu_T *topmenu = menu; topmenu != NULL; topmenu = topmenu->next) { + if (!menu_is_hidden(topmenu->dname)) { + tv_list_append_string(l, topmenu->dname, -1); + } + } + return; + } + tv_dict_add_str(dict, S_LEN("name"), menu->name); tv_dict_add_str(dict, S_LEN("display"), menu->dname); if (menu->actext != NULL) { @@ -1990,6 +2003,6 @@ void f_menu_info(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (menu->modes & modes) { - menuitem_getinfo(menu, modes, retdict); + menuitem_getinfo(menu_name, menu, modes, retdict); } } diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index 24d7420751..28db050f82 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -362,6 +362,9 @@ func Test_menu_info() \ shortcut: '', modes: ' ', submenus: ['menu']}, \ menu_info(']Test')) unmenu ]Test + + " Test for getting all the top-level menu names + call assert_notequal(menu_info('').submenus, []) endfunc " Test for <special> keyword in a menu with 'cpo' containing '<' |