Fix preselect

This commit is contained in:
hrsh7th
2021-08-26 22:40:18 +09:00
parent c627f44f81
commit c2fefe00e5

View File

@@ -116,15 +116,15 @@ menu.update = check.wrap(function(self, ctx, sources)
local items = {} local items = {}
local abbrs = {} local abbrs = {}
local preselect = 0 local preselect = 0
for i, e in ipairs(entries) do for _, e in ipairs(entries) do
if preselect == 0 and e.completion_item.preselect and config.get().preselect ~= types.cmp.PreselectMode.None then
preselect = i
end
local item = e:get_vim_item(offset) local item = e:get_vim_item(offset)
if not abbrs[item.abbr] or item.dup == 1 then if not abbrs[item.abbr] or item.dup == 1 then
table.insert(items, item) table.insert(items, item)
abbrs[item.abbr] = true abbrs[item.abbr] = true
if preselect == 0 and e.completion_item.preselect and config.get().preselect ~= types.cmp.PreselectMode.None then
preselect = #items
end
end end
end end
@@ -166,7 +166,7 @@ menu.show = function(self)
vim.cmd('set completeopt=' .. config.get().completion.completeopt) vim.cmd('set completeopt=' .. config.get().completion.completeopt)
end end
vim.fn.complete(self.offset, self.items) vim.fn.complete(self.offset, self.items)
if self.preselect > 0 then if self.preselect > 1 then
vim.api.nvim_select_popupmenu_item(self.preselect - 1, false, false, {}) vim.api.nvim_select_popupmenu_item(self.preselect - 1, false, false, {})
end end
vim.cmd('set completeopt=' .. completeopt) vim.cmd('set completeopt=' .. completeopt)