mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(completion): support selecting item via API from Lua mapping
This commit is contained in:
parent
7165e7770d
commit
c7aa64631d
@ -1082,6 +1082,8 @@ static int insert_handle_key(InsertState *s)
|
|||||||
map_execute_lua();
|
map_execute_lua();
|
||||||
|
|
||||||
check_pum:
|
check_pum:
|
||||||
|
// nvim_select_popupmenu_item() can be called from the handling of
|
||||||
|
// K_EVENT, K_COMMAND, or K_LUA.
|
||||||
// TODO(bfredl): Not entirely sure this indirection is necessary
|
// TODO(bfredl): Not entirely sure this indirection is necessary
|
||||||
// but doing like this ensures using nvim_select_popupmenu_item is
|
// but doing like this ensures using nvim_select_popupmenu_item is
|
||||||
// equivalent to selecting the item with a typed key.
|
// equivalent to selecting the item with a typed key.
|
||||||
@ -4986,7 +4988,7 @@ void ins_compl_check_keys(int frequency, int in_compl_func)
|
|||||||
*/
|
*/
|
||||||
static int ins_compl_key2dir(int c)
|
static int ins_compl_key2dir(int c)
|
||||||
{
|
{
|
||||||
if (c == K_EVENT || c == K_COMMAND) {
|
if (c == K_EVENT || c == K_COMMAND || c == K_LUA) {
|
||||||
return pum_want.item < pum_selected_item ? BACKWARD : FORWARD;
|
return pum_want.item < pum_selected_item ? BACKWARD : FORWARD;
|
||||||
}
|
}
|
||||||
if (c == Ctrl_P || c == Ctrl_L
|
if (c == Ctrl_P || c == Ctrl_L
|
||||||
@ -5016,7 +5018,7 @@ static int ins_compl_key2count(int c)
|
|||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
|
|
||||||
if (c == K_EVENT || c == K_COMMAND) {
|
if (c == K_EVENT || c == K_COMMAND || c == K_LUA) {
|
||||||
int offset = pum_want.item - pum_selected_item;
|
int offset = pum_want.item - pum_selected_item;
|
||||||
return abs(offset);
|
return abs(offset);
|
||||||
}
|
}
|
||||||
@ -5050,6 +5052,7 @@ static bool ins_compl_use_match(int c)
|
|||||||
return false;
|
return false;
|
||||||
case K_EVENT:
|
case K_EVENT:
|
||||||
case K_COMMAND:
|
case K_COMMAND:
|
||||||
|
case K_LUA:
|
||||||
return pum_want.active && pum_want.insert;
|
return pum_want.active && pum_want.insert;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,6 +10,7 @@ local funcs = helpers.funcs
|
|||||||
local get_pathsep = helpers.get_pathsep
|
local get_pathsep = helpers.get_pathsep
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
|
local exec_lua = helpers.exec_lua
|
||||||
|
|
||||||
describe('ui/ext_popupmenu', function()
|
describe('ui/ext_popupmenu', function()
|
||||||
local screen
|
local screen
|
||||||
@ -369,6 +370,62 @@ describe('ui/ext_popupmenu', function()
|
|||||||
{1:~ }|
|
{1:~ }|
|
||||||
{2:-- INSERT --} |
|
{2:-- INSERT --} |
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
command('iunmap <f1>')
|
||||||
|
command('iunmap <f2>')
|
||||||
|
command('iunmap <f3>')
|
||||||
|
exec_lua([[
|
||||||
|
vim.keymap.set('i', '<f1>', function() vim.api.nvim_select_popupmenu_item(2, true, false, {}) end)
|
||||||
|
vim.keymap.set('i', '<f2>', function() vim.api.nvim_select_popupmenu_item(-1, false, false, {}) end)
|
||||||
|
vim.keymap.set('i', '<f3>', function() vim.api.nvim_select_popupmenu_item(1, false, true, {}) end)
|
||||||
|
]])
|
||||||
|
feed('<C-r>=TestComplete()<CR>')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
foo^ |
|
||||||
|
{6:fo x the foo }{1: }|
|
||||||
|
{7:bar }{1: }|
|
||||||
|
{7:spam }{1: }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:-- INSERT --} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<f1>')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
spam^ |
|
||||||
|
{7:fo x the foo }{1: }|
|
||||||
|
{7:bar }{1: }|
|
||||||
|
{6:spam }{1: }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:-- INSERT --} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<f2>')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
spam^ |
|
||||||
|
{7:fo x the foo }{1: }|
|
||||||
|
{7:bar }{1: }|
|
||||||
|
{7:spam }{1: }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:-- INSERT --} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<f3>')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
bar^ |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:-- INSERT --} |
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function source_complete_month()
|
local function source_complete_month()
|
||||||
|
Loading…
Reference in New Issue
Block a user