Skip to content

Commit

Permalink
fix(view): check in get_selected_index
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Jul 15, 2024
1 parent e1757ae commit 3117cbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/cmp/view/custom_entries_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ custom_entries_view.info = function(self)
end

custom_entries_view.get_selected_index = function(self)
if self:visible() and self.active then
if self:visible() and self.entries_win:option('cursorline') then
return vim.api.nvim_win_get_cursor(self.entries_win.win)[1]
end
end
Expand Down
15 changes: 8 additions & 7 deletions lua/cmp/view/native_entries_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ native_entries_view.preselect = function(self, index)
end

native_entries_view.get_selected_index = function(self)
if self:visible() and (vim.v.completed_item or {}).word then
return vim.fn.complete_info({ 'selected' }).selected
if self:visible() then
local idx = vim.fn.complete_info({ 'selected' }).selected
if idx > -1 then
return math.max(0, idx) + 1
end
end
end

Expand Down Expand Up @@ -169,11 +172,9 @@ native_entries_view.get_first_entry = function(self)
end

native_entries_view.get_selected_entry = function(self)
if self:visible() then
local idx = self:get_selected_index()
if idx > -1 then
return self.entries[math.max(0, idx) + 1]
end
local idx = self:get_selected_index()
if idx then
return self.entries[idx]
end
end

Expand Down
5 changes: 3 additions & 2 deletions lua/cmp/view/wildmenu_entries_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ wildmenu_entries_view.get_first_entry = function(self)
end

wildmenu_entries_view.get_selected_entry = function(self)
if self:visible() and self.active then
return self.entries[self:get_selected_index()]
local idx = self:get_selected_index()
if idx then
return self.entries[idx]
end
end

Expand Down

0 comments on commit 3117cbf

Please sign in to comment.