15
15
--- @field hide fun ()
16
16
---
17
17
--- @field get_selected_item fun (): blink.cmp.CompletionItem ?
18
- --- @field select fun ( idx ?: number )
18
+ --- @field select fun ( idx ?: number , opts ?: { undo_preview ?: boolean } )
19
19
--- @field select_next fun ()
20
20
--- @field select_prev fun ()
21
21
---
@@ -74,7 +74,7 @@ function list.show(context, items)
74
74
end
75
75
76
76
-- todo: some logic to maintain the selection if the user moved the cursor?
77
- list .select (list .config .selection == ' preselect' and 1 or nil )
77
+ list .select (list .config .selection == ' preselect' and 1 or nil , { undo_preview = false } )
78
78
end
79
79
80
80
function list .fuzzy (context , items )
@@ -91,11 +91,15 @@ function list.hide() list.hide_emitter:emit({ context = list.context }) end
91
91
92
92
function list .get_selected_item () return list .items [list .selected_item_idx ] end
93
93
94
- function list .select (idx )
94
+ function list .select (idx , opts )
95
+ opts = opts or {}
95
96
local item = list .items [idx ]
96
97
97
- list .undo_preview ()
98
- if list .config .selection == ' auto_insert' and item then list .apply_preview (item ) end
98
+ require (' blink.cmp.completion.trigger' ).suppress_events_for_callback (function ()
99
+ -- default to undoing the preview
100
+ if opts .undo_preview ~= false then list .undo_preview () end
101
+ if list .config .selection == ' auto_insert' and item then list .apply_preview (item ) end
102
+ end )
99
103
100
104
list .selected_item_idx = idx
101
105
list .select_emitter :emit ({ idx = idx , item = item , items = list .items , context = list .context })
@@ -155,14 +159,12 @@ function list.undo_preview()
155
159
end
156
160
157
161
function list .apply_preview (item )
158
- require (' blink.cmp.completion.trigger' ).suppress_events_for_callback (function ()
159
- -- undo the previous preview if it exists
160
- if list .preview_undo_text_edit ~= nil then
161
- require (' blink.cmp.lib.text_edits' ).apply ({ list .preview_undo_text_edit })
162
- end
163
- -- apply the new preview
164
- list .preview_undo_text_edit = require (' blink.cmp.completion.accept.preview' )(item )
165
- end )
162
+ -- undo the previous preview if it exists
163
+ if list .preview_undo_text_edit ~= nil then
164
+ require (' blink.cmp.lib.text_edits' ).apply ({ list .preview_undo_text_edit })
165
+ end
166
+ -- apply the new preview
167
+ list .preview_undo_text_edit = require (' blink.cmp.completion.accept.preview' )(item )
166
168
end
167
169
168
170
---- ------ Accept ----------
0 commit comments