feat: select_next_item and select_prev_item support "count" option. deafults to 1 (#1262)

User can increase count value to select item with pagedown/pageup.

- cmp.select_prev_item({ behavior = behavior, count = 8 })
- cmp.select_next_item({ behavior = behavior, count = 8 })
This commit is contained in:
ADoyle
2022-11-09 18:26:20 +08:00
committed by GitHub
parent c8d4afdad6
commit bdfadc1238
5 changed files with 72 additions and 33 deletions

View File

@@ -131,6 +131,7 @@ end)
cmp.select_next_item = cmp.sync(function(option)
option = option or {}
option.behavior = option.behavior or cmp.SelectBehavior.Insert
option.count = option.count or 1
if cmp.core.view:visible() then
local release = cmp.core:suspend()
@@ -139,9 +140,9 @@ cmp.select_next_item = cmp.sync(function(option)
return true
elseif vim.fn.pumvisible() == 1 then
if option.behavior == cmp.SelectBehavior.Insert then
feedkeys.call(keymap.t('<C-n>'), 'in')
feedkeys.call(keymap.t(string.format('%s<C-n>', option.count)), 'in')
else
feedkeys.call(keymap.t('<Down>'), 'in')
feedkeys.call(keymap.t(string.format('%s<Down>', option.count)), 'in')
end
return true
end
@@ -152,6 +153,7 @@ end)
cmp.select_prev_item = cmp.sync(function(option)
option = option or {}
option.behavior = option.behavior or cmp.SelectBehavior.Insert
option.count = option.count or 1
if cmp.core.view:visible() then
local release = cmp.core:suspend()
@@ -160,9 +162,9 @@ cmp.select_prev_item = cmp.sync(function(option)
return true
elseif vim.fn.pumvisible() == 1 then
if option.behavior == cmp.SelectBehavior.Insert then
feedkeys.call(keymap.t('<C-p>'), 'in')
feedkeys.call(keymap.t(string.format('%s<C-p>', option.count)), 'in')
else
feedkeys.call(keymap.t('<Up>'), 'in')
feedkeys.call(keymap.t(string.format('%s<Up>', option.count)), 'in')
end
return true
end