Refactor a bit
This commit is contained in:
@@ -108,7 +108,6 @@ cmp.close = cmp.sync(function()
|
||||
if cmp.core.view:visible() then
|
||||
local release = cmp.core:suspend()
|
||||
cmp.core.view:close()
|
||||
cmp.core:reset()
|
||||
vim.schedule(release)
|
||||
return true
|
||||
else
|
||||
@@ -131,6 +130,7 @@ end)
|
||||
---Select next item if possible
|
||||
cmp.select_next_item = cmp.sync(function(option)
|
||||
option = option or {}
|
||||
option.behavior = option.behavior or cmp.SelectBehavior.Insert
|
||||
|
||||
if cmp.core.view:visible() then
|
||||
local release = cmp.core:suspend()
|
||||
@@ -138,8 +138,7 @@ cmp.select_next_item = cmp.sync(function(option)
|
||||
vim.schedule(release)
|
||||
return true
|
||||
elseif vim.fn.pumvisible() == 1 then
|
||||
-- Special handling for native pum. Required to facilitate key mapping processing.
|
||||
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
||||
if option.behavior == cmp.SelectBehavior.Insert then
|
||||
feedkeys.call(keymap.t('<C-n>'), 'in')
|
||||
else
|
||||
feedkeys.call(keymap.t('<Down>'), 'in')
|
||||
@@ -152,6 +151,7 @@ end)
|
||||
---Select prev item if possible
|
||||
cmp.select_prev_item = cmp.sync(function(option)
|
||||
option = option or {}
|
||||
option.behavior = option.behavior or cmp.SelectBehavior.Insert
|
||||
|
||||
if cmp.core.view:visible() then
|
||||
local release = cmp.core:suspend()
|
||||
@@ -159,8 +159,7 @@ cmp.select_prev_item = cmp.sync(function(option)
|
||||
vim.schedule(release)
|
||||
return true
|
||||
elseif vim.fn.pumvisible() == 1 then
|
||||
-- Special handling for native pum. Required to facilitate key mapping processing.
|
||||
if (option.behavior or cmp.SelectBehavior.Insert) == cmp.SelectBehavior.Insert then
|
||||
if option.behavior == cmp.SelectBehavior.Insert then
|
||||
feedkeys.call(keymap.t('<C-p>'), 'in')
|
||||
else
|
||||
feedkeys.call(keymap.t('<Up>'), 'in')
|
||||
@@ -183,25 +182,35 @@ end)
|
||||
---Confirm completion
|
||||
cmp.confirm = cmp.sync(function(option, callback)
|
||||
option = option or {}
|
||||
callback = callback or function() end
|
||||
option.select = option.select or false
|
||||
option.behavior = option.behavior or cmp.ConfirmBehavior.Insert
|
||||
callback = callback or (function() end)
|
||||
|
||||
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
|
||||
if e then
|
||||
cmp.core:confirm(e, {
|
||||
behavior = option.behavior,
|
||||
}, function()
|
||||
callback()
|
||||
cmp.core:complete(cmp.core:get_context({ reason = cmp.ContextReason.TriggerOnly }))
|
||||
end)
|
||||
return true
|
||||
else
|
||||
-- Special handling for native puma. Required to facilitate key mapping processing.
|
||||
if vim.fn.complete_info({ 'selected' }).selected ~= -1 then
|
||||
feedkeys.call(keymap.t('<C-y>'), 'in')
|
||||
if cmp.core.view:visible() then
|
||||
local e = cmp.core.view:get_selected_entry()
|
||||
if not e and option.select then
|
||||
e = cmp.core.view:get_first_entry()
|
||||
end
|
||||
if e then
|
||||
cmp.core:confirm(e, {
|
||||
behavior = option.behavior,
|
||||
}, function()
|
||||
callback()
|
||||
cmp.core:complete(cmp.core:get_context({ reason = cmp.ContextReason.TriggerOnly }))
|
||||
end)
|
||||
return true
|
||||
end
|
||||
elseif vim.fn.pumvisible() == 1 then
|
||||
local index = vim.fn.complete_info({ 'selected' }).selected
|
||||
if index == -1 and option.select then
|
||||
index = 0
|
||||
end
|
||||
if index ~= -1 then
|
||||
vim.api.nvim_select_popupmenu_item(index, true, true, {})
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
---Show status
|
||||
|
||||
Reference in New Issue
Block a user