fix(view): check in get_selected_index (#1993)

This commit is contained in:
NAKAI Tsuyoshi
2024-07-16 10:33:54 +09:00
committed by GitHub
parent e1757aea61
commit d818fd0624
3 changed files with 12 additions and 10 deletions

View File

@@ -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
@@ -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