ui: allow external ui to draw wildmenu

Co-authored-by: Björn Linse <bjorn.linse@gmail.com>
Updated docs and tests.
This commit is contained in:
Dongdong Zhou 2017-02-24 06:12:34 +00:00 committed by Björn Linse
parent 2a3bcd1ff8
commit 39e83fa7cb
4 changed files with 147 additions and 5 deletions

View File

@ -28,6 +28,7 @@ a dictionary with these (optional) keys:
`ext_popupmenu` Externalize the popupmenu. |ui-popupmenu| `ext_popupmenu` Externalize the popupmenu. |ui-popupmenu|
`ext_tabline` Externalize the tabline. |ui-tabline| `ext_tabline` Externalize the tabline. |ui-tabline|
`ext_cmdline` Externalize the cmdline. |ui-cmdline| `ext_cmdline` Externalize the cmdline. |ui-cmdline|
`ext_wildmenu` Externalize the tabline. |ui-ext-wildmenu|
Nvim will then send msgpack-rpc notifications, with the method name "redraw" Nvim will then send msgpack-rpc notifications, with the method name "redraw"
and a single argument, an array of screen update events. and a single argument, an array of screen update events.
@ -286,5 +287,23 @@ Only sent if `ext_cmdline` option is set in |ui-options|
["cmdline_block_hide"] ["cmdline_block_hide"]
Hide the block. Hide the block.
==============================================================================
Wildmenu Events *ui-wildmenu*
Only sent if `ext_wildmenu` option is set in |ui-options|
["wildmenu_show", items]
When `ext_wildmenu` is set to true, nvim will not draw the
wildmenu on the grid, instead when the wildmenu is to be displayed
this update is sent. `items` is an array of the completion items.
["wildmenu_select", selected]
An item in the currently displayed wildmenu is selected. `selected`
is either a zero-based index into the array of items from the last
wildmenu event, or -1 if no item is selected.
["wildmenu_hide"]
The wildmenu is hidden.
============================================================================== ==============================================================================
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View File

@ -65,6 +65,7 @@ void popupmenu_hide(void)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void popupmenu_select(Integer selected) void popupmenu_select(Integer selected)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void tabline_update(Tabpage current, Array tabs) void tabline_update(Tabpage current, Array tabs)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
@ -84,4 +85,10 @@ void cmdline_block_append(Array lines)
void cmdline_block_hide(void) void cmdline_block_hide(void)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void wildmenu_show(Array content)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void wildmenu_select(Integer selected)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void wildmenu_hide(void)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
#endif // NVIM_API_UI_EVENTS_IN_H #endif // NVIM_API_UI_EVENTS_IN_H

View File

@ -534,6 +534,9 @@ static int command_line_execute(VimState *state, int key)
if (!(s->c == p_wc && KeyTyped) && s->c != p_wcm if (!(s->c == p_wc && KeyTyped) && s->c != p_wcm
&& s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A && s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A
&& s->c != Ctrl_L) { && s->c != Ctrl_L) {
if (ui_is_external(kUIWildmenu)) {
ui_call_wildmenu_hide();
}
if (s->xpc.xp_numfiles != -1) { if (s->xpc.xp_numfiles != -1) {
(void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE); (void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE);
} }
@ -3515,11 +3518,17 @@ ExpandOne (
else else
findex = -1; findex = -1;
} }
if (p_wmnu) if (p_wmnu) {
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, if (ui_is_external(kUIWildmenu)) {
findex, cmd_showtail); ui_call_wildmenu_select(findex);
if (findex == -1) } else {
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
findex, cmd_showtail);
}
}
if (findex == -1) {
return vim_strsave(orig_save); return vim_strsave(orig_save);
}
return vim_strsave(xp->xp_files[findex]); return vim_strsave(xp->xp_files[findex]);
} else } else
return NULL; return NULL;
@ -3876,6 +3885,15 @@ static int showmatches(expand_T *xp, int wildmenu)
showtail = cmd_showtail; showtail = cmd_showtail;
} }
if (ui_is_external(kUIWildmenu)) {
Array args = ARRAY_DICT_INIT;
for (i = 0; i < num_files; i++) {
ADD(args, STRING_OBJ(cstr_to_string((char *)files_found[i])));
}
ui_call_wildmenu_show(args);
return EXPAND_OK;
}
if (!wildmenu) { if (!wildmenu) {
msg_didany = FALSE; /* lines_left will be set */ msg_didany = FALSE; /* lines_left will be set */
msg_start(); /* prepare for paging */ msg_start(); /* prepare for paging */
@ -6128,4 +6146,3 @@ static void set_search_match(pos_T *t)
coladvance((colnr_T)MAXCOL); coladvance((colnr_T)MAXCOL);
} }
} }

View File

@ -179,3 +179,102 @@ describe('command line completion', function()
]]) ]])
end) end)
end) end)
describe('External wildmenu', function()
local screen
local items, selected = nil, nil
before_each(function()
clear()
screen = Screen.new(25, 5)
screen:attach({rgb=true, ext_wildmenu=true})
screen:set_on_event_handler(function(name, data)
if name == "wildmenu_show" then
items = data[1]
elseif name == "wildmenu_select" then
selected = data[1]
elseif name == "wildmenu_hide" then
items, selected = nil, nil
end
end)
end)
after_each(function()
screen:detach()
end)
it('works with :sign <tab>', function()
local expected = {
'define',
'jump',
'list',
'place',
'undefine',
'unplace',
}
command('set wildmode=full')
command('set wildmenu')
feed(':sign <tab>')
screen:expect([[
|
~ |
~ |
~ |
:sign define^ |
]], nil, nil, function()
eq(expected, items)
eq(0, selected)
end)
feed('<tab>')
screen:expect([[
|
~ |
~ |
~ |
:sign jump^ |
]], nil, nil, function()
eq(expected, items)
eq(1, selected)
end)
feed('<left><left>')
screen:expect([[
|
~ |
~ |
~ |
:sign ^ |
]], nil, nil, function()
eq(expected, items)
eq(-1, selected)
end)
feed('<right>')
screen:expect([[
|
~ |
~ |
~ |
:sign define^ |
]], nil, nil, function()
eq(expected, items)
eq(0, selected)
end)
feed('a')
screen:expect([[
|
~ |
~ |
~ |
:sign definea^ |
]], nil, nil, function()
eq(nil, items)
eq(nil, selected)
end)
end)
end)