This commit is contained in:
hrsh7th
2022-08-20 21:58:53 +09:00
parent 7e67df513a
commit 3cc0c182ec
2 changed files with 8 additions and 9 deletions

View File

@@ -125,7 +125,7 @@ custom_entries_view.open = function(self, offset, entries)
local entries_buf = self.entries_win:get_buffer()
local lines = {}
local dedup = {}
local preselect = 0
local preselect_index = 0
for _, e in ipairs(entries) do
local view = e:get_view(offset, entries_buf)
if view.dup == 1 or not dedup[e.completion_item.label] then
@@ -135,8 +135,8 @@ custom_entries_view.open = function(self, offset, entries)
self.column_width.menu = math.max(self.column_width.menu, view.menu.width)
table.insert(self.entries, e)
table.insert(lines, ' ')
if preselect == 0 and e.completion_item.preselect then
preselect = #self.entries
if preselect_index == 0 and e.completion_item.preselect then
preselect_index = #self.entries
end
end
end
@@ -187,8 +187,8 @@ custom_entries_view.open = function(self, offset, entries)
for i = 1, math.floor(n / 2) do
self.entries[i], self.entries[n - i + 1] = self.entries[n - i + 1], self.entries[i]
end
if preselect ~= 0 then
preselect = #self.entries - preselect + 1
if preselect_index ~= 0 then
preselect_index = #self.entries - preselect_index + 1
end
end
@@ -207,8 +207,8 @@ custom_entries_view.open = function(self, offset, entries)
})
-- always set cursor when starting. It will be adjusted on the call to _select
vim.api.nvim_win_set_cursor(self.entries_win.win, { 1, 0 })
if preselect > 0 and config.get().preselect == types.cmp.PreselectMode.Item then
self:_select(preselect, { behavior = types.cmp.SelectBehavior.Select })
if preselect_index > 0 and config.get().preselect == types.cmp.PreselectMode.Item then
self:_select(preselect_index, { behavior = types.cmp.SelectBehavior.Select })
elseif not string.match(config.get().completion.completeopt, 'noselect') then
if self:is_direction_top_down() then
self:_select(1, { behavior = types.cmp.SelectBehavior.Select })