File tree 5 files changed +36
-5
lines changed
5 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,12 @@ cmp.visible = cmp.sync(function()
88
88
return cmp .core .view :visible () or vim .fn .pumvisible () == 1
89
89
end )
90
90
91
+ --- Get what number candidates are currently selected.
92
+ --- If not selected, nil is returned.
93
+ cmp .get_selected_index = cmp .sync (function ()
94
+ return cmp .core .view :get_selected_index ()
95
+ end )
96
+
91
97
--- Get current selected entry or nil
92
98
cmp .get_selected_entry = cmp .sync (function ()
93
99
return cmp .core .view :get_selected_entry ()
Original file line number Diff line number Diff line change @@ -211,6 +211,13 @@ view.scroll_docs = function(self, delta)
211
211
self .docs_view :scroll (delta )
212
212
end
213
213
214
+ --- Get what number candidates are currently selected.
215
+ --- If not selected, nil is returned.
216
+ --- @return integer | nil
217
+ view .get_selected_index = function (self )
218
+ return self :_get_entries_view ():get_selected_index ()
219
+ end
220
+
214
221
--- Select prev menu item.
215
222
--- @param option cmp.SelectOption
216
223
view .select_next_item = function (self , option )
Original file line number Diff line number Diff line change @@ -306,9 +306,15 @@ custom_entries_view.info = function(self)
306
306
return self .entries_win :info ()
307
307
end
308
308
309
+ custom_entries_view .get_selected_index = function (self )
310
+ if self :visible () and self .active then
311
+ return vim .api .nvim_win_get_cursor (self .entries_win .win )[1 ]
312
+ end
313
+ end
314
+
309
315
custom_entries_view .select_next_item = function (self , option )
310
316
if self :visible () then
311
- local cursor = vim . api . nvim_win_get_cursor ( self . entries_win . win )[ 1 ]
317
+ local cursor = self : get_selected_index ()
312
318
local is_top_down = self :is_direction_top_down ()
313
319
local last = # self .entries
314
320
345
351
346
352
custom_entries_view .select_prev_item = function (self , option )
347
353
if self :visible () then
348
- local cursor = vim . api . nvim_win_get_cursor ( self . entries_win . win )[ 1 ]
354
+ local cursor = self : get_selected_index ()
349
355
local is_top_down = self :is_direction_top_down ()
350
356
local last = # self .entries
351
357
402
408
403
409
custom_entries_view .get_selected_entry = function (self )
404
410
if self :visible () and self .entries_win :option (' cursorline' ) then
405
- return self .entries [vim . api . nvim_win_get_cursor ( self . entries_win . win )[ 1 ] ]
411
+ return self .entries [self : get_selected_index () ]
406
412
end
407
413
end
408
414
Original file line number Diff line number Diff line change @@ -116,6 +116,12 @@ native_entries_view.preselect = function(self, index)
116
116
end
117
117
end
118
118
119
+ native_entries_view .get_selected_index = function (self )
120
+ if self :visible () and (vim .v .completed_item or {}).word then
121
+ return vim .fn .complete_info ({ ' selected' }).selected
122
+ end
123
+ end
124
+
119
125
native_entries_view .select_next_item = function (self , option )
120
126
local callback = function ()
121
127
self .event :emit (' change' )
164
170
165
171
native_entries_view .get_selected_entry = function (self )
166
172
if self :visible () then
167
- local idx = vim . fn . complete_info ({ ' selected ' }). selected
173
+ local idx = self : get_selected_index ()
168
174
if idx > - 1 then
169
175
return self .entries [math.max (0 , idx ) + 1 ]
170
176
end
Original file line number Diff line number Diff line change @@ -179,6 +179,12 @@ wildmenu_entries_view.info = function(self)
179
179
return self .entries_win :info ()
180
180
end
181
181
182
+ wildmenu_entries_view .get_selected_index = function (self )
183
+ if self :visible () and self .active then
184
+ return self .selected_index
185
+ end
186
+ end
187
+
182
188
wildmenu_entries_view .select_next_item = function (self , option )
183
189
if self :visible () then
184
190
local cursor
224
230
225
231
wildmenu_entries_view .get_selected_entry = function (self )
226
232
if self :visible () and self .active then
227
- return self .entries [self . selected_index ]
233
+ return self .entries [self : get_selected_index () ]
228
234
end
229
235
end
230
236
You can’t perform that action at this time.
0 commit comments