Skip to content

Commit

Permalink
Merge 1f61387 into 01e53a5
Browse files Browse the repository at this point in the history
  • Loading branch information
KillTheMule committed Oct 2, 2017
2 parents 01e53a5 + 1f61387 commit 2f8b8e7
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/nvim/menu.c
Expand Up @@ -682,6 +682,10 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
tv_dict_add_str(dict, S_LEN("shortcut"), buf);
}

if (menu->actext) {
tv_dict_add_str(dict, S_LEN("actext"), (char *)menu->actext);
}

if (menu->modes & MENU_TIP_MODE && menu->strings[MENU_INDEX_TIP]) {
tv_dict_add_str(dict, S_LEN("tooltip"),
(char *)menu->strings[MENU_INDEX_TIP]);
Expand All @@ -695,11 +699,9 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
for (int bit = 0; bit < MENU_MODES; bit++) {
if ((menu->modes & modes & (1 << bit)) != 0) {
dict_T *impl = tv_dict_alloc();
if (*menu->strings[bit] == NUL) {
tv_dict_add_str(impl, S_LEN("rhs"), (char *)"<Nop>");
} else {
tv_dict_add_str(impl, S_LEN("rhs"), (char *)menu->strings[bit]);
}
tv_dict_add_allocated_str(impl, S_LEN("rhs"),
str2special_save((char *)menu->strings[bit],
false, false));
tv_dict_add_nr(impl, S_LEN("silent"), menu->silent[bit]);
tv_dict_add_nr(impl, S_LEN("enabled"),
(menu->enabled & (1 << bit)) ? 1 : 0);
Expand Down
252 changes: 250 additions & 2 deletions test/functional/ex_cmds/menu_spec.lua
Expand Up @@ -107,7 +107,7 @@ describe('menu_get', function()
sid = 1,
noremap = 1,
enabled = 1,
rhs = "inormal\27",
rhs = "inormal<Esc>",
silent = 0
},
v = {
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('menu_get', function()
sid = 1,
noremap = 1,
enabled = 1,
rhs = "\18\"",
rhs = "<C-R>\"",
silent = 0
},
n = {
Expand Down Expand Up @@ -379,5 +379,253 @@ describe('menu_get', function()
}
eq(expected, m)
end)
end)

describe('menu_get', function()

before_each(function()
clear()
end)

it('prettyprints special chars', function()
clear()
command('nnoremenu &Test.Test inormal<ESC>')
command('inoremenu &Test.Test2 <Tab><Esc>')
command('vnoremenu &Test.Test3 yA<C-R>0<Tab>xyz<Esc>')
command('inoremenu &Test.Test4 <c-r>*')
command('inoremenu &Test.Test5 <c-R>+')
command('nnoremenu &Test.Test6 <Nop>')
command('nnoremenu &Test.Test7 <NOP>')
command('nnoremenu &Test.Test8 <NoP>')
command('nnoremenu &Test.Test9 ""')

local m = funcs.menu_get("");
local expected = {
{
shortcut = "T",
hidden = 0,
submenus = {
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "inormal<Esc>",
silent = 0
}
},
name = "Test",
hidden = 0
},
{
priority = 500,
mappings = {
i = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "<Tab><Esc>",
silent = 0
}
},
name = "Test2",
hidden = 0
},
{
priority = 500,
mappings = {
s = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "yA<C-R>0<Tab>xyz<Esc>",
silent = 0
},
v = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "yA<C-R>0<Tab>xyz<Esc>",
silent = 0
}
},
name = "Test3",
hidden = 0
},
{
priority = 500,
mappings = {
i = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "<C-R>*",
silent = 0
}
},
name = "Test4",
hidden = 0
},
{
priority = 500,
mappings = {
i = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "<C-R>+",
silent = 0
}
},
name = "Test5",
hidden = 0
},
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "",
silent = 0
}
},
name = "Test6",
hidden = 0
},
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "",
silent = 0
}
},
name = "Test7",
hidden = 0
},
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "",
silent = 0
}
},
name = "Test8",
hidden = 0
},
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "\"\"",
silent = 0
}
},
name = "Test9",
hidden = 0
}
},
priority = 500,
name = "Test"
}
}

eq(m, expected)
end)

it('works with right-aligned text and spaces', function()
clear()
command('nnoremenu &Test<Tab>Y.Test<Tab>X\\ x inormal<Alt-j>')
command('nnoremenu &Test\\ 1.Test\\ 2 Wargl')
command('nnoremenu &Test4.Test<Tab>3 i space<Esc>')

local m = funcs.menu_get("");
local expected = {
{
shortcut = "T",
hidden = 0,
actext = "Y",
submenus = {
{
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "inormal<Alt-j>",
silent = 0
}
},
hidden = 0,
actext = "X x",
priority = 500,
name = "Test"
}
},
priority = 500,
name = "Test"
},
{
shortcut = "T",
hidden = 0,
submenus = {
{
priority = 500,
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "Wargl",
silent = 0
}
},
name = "Test 2",
hidden = 0
}
},
priority = 500,
name = "Test 1"
},
{
shortcut = "T",
hidden = 0,
submenus = {
{
mappings = {
n = {
sid = 1,
noremap = 1,
enabled = 1,
rhs = "i space<Esc>",
silent = 0
}
},
hidden = 0,
actext = "3",
priority = 500,
name = "Test"
}
},
priority = 500,
name = "Test4"
}
}

eq(m, expected)
end)
end)

0 comments on commit 2f8b8e7

Please sign in to comment.