diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index da2310d..2c72fe6 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -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 }) diff --git a/lua/cmp/view/native_entries_view.lua b/lua/cmp/view/native_entries_view.lua index a74c63d..643827c 100644 --- a/lua/cmp/view/native_entries_view.lua +++ b/lua/cmp/view/native_entries_view.lua @@ -77,8 +77,7 @@ native_entries_view.open = function(self, offset, entries) end native_entries_view.close = function(self) - if api.is_suitable_mode() and self:visible() then - vim.fn.complete(1, {}) + if api.is_insert_mode() and self:visible() then vim.api.nvim_select_popupmenu_item(-1, false, true, {}) end self.offset = -1