12
12
--- @field auto_show boolean
13
13
--- @field context blink.cmp.Context ?
14
14
--- @field event_targets blink.cmp.CompletionWindowEventTargets
15
+ --- @field preview_undo_text_edit ? lsp.TextEdit
16
+ --- @field preview_context_id ? number
15
17
---
16
18
--- @field setup fun (): blink.cmp.CompletionWindow
17
19
---
25
27
--- @field listen_on_position_update fun ( callback : fun ())
26
28
---
27
29
--- @field accept fun (): boolean ?
30
+ --- @field undo_preview fun ()
28
31
---
29
32
--- @field select fun ( line : number , skip_auto_insert ?: boolean )
30
33
--- @field select_next fun ( opts ?: { skip_auto_insert ?: boolean })
@@ -200,15 +203,25 @@ function autocomplete.accept()
200
203
if selected_item == nil then return end
201
204
202
205
-- undo the preview if it exists
203
- if autocomplete .preview_text_edit ~= nil and autocomplete .preview_context_id == autocomplete .context .id then
204
- text_edits_lib .undo (autocomplete .preview_text_edit )
206
+ if autocomplete .preview_undo_text_edit ~= nil and autocomplete .preview_context_id == autocomplete .context .id then
207
+ text_edits_lib .apply ({ autocomplete .preview_undo_text_edit })
208
+ autocomplete .preview_undo_text_edit = nil
209
+ autocomplete .preview_context_id = nil
205
210
end
206
211
207
212
-- apply
208
213
require (' blink.cmp.accept' )(context , selected_item )
209
214
return true
210
215
end
211
216
217
+ function autocomplete .undo_preview ()
218
+ if autocomplete .preview_undo_text_edit ~= nil and autocomplete .preview_context_id == autocomplete .context .id then
219
+ text_edits_lib .apply ({ autocomplete .preview_undo_text_edit })
220
+ autocomplete .preview_undo_text_edit = nil
221
+ autocomplete .preview_context_id = nil
222
+ end
223
+ end
224
+
212
225
function autocomplete .select (line , skip_auto_insert )
213
226
autocomplete .set_has_selected (true )
214
227
vim .api .nvim_win_set_cursor (autocomplete .win :get_win (), { line , 0 })
@@ -218,9 +231,12 @@ function autocomplete.select(line, skip_auto_insert)
218
231
-- when auto_insert is enabled, we immediately apply the text edit
219
232
if config .windows .autocomplete .selection == ' auto_insert' and selected_item ~= nil and not skip_auto_insert then
220
233
require (' blink.cmp.trigger.completion' ).suppress_events_for_callback (function ()
221
- if autocomplete .preview_context_id ~= autocomplete .context .id then autocomplete .preview_text_edit = nil end
222
- autocomplete .preview_text_edit =
223
- require (' blink.cmp.accept.preview' )(selected_item , autocomplete .preview_text_edit )
234
+ -- undo the previous preview if it exists
235
+ if autocomplete .preview_context_id == autocomplete .context .id and autocomplete .preview_undo_text_edit ~= nil then
236
+ require (' blink.cmp.accept.text-edits' ).apply ({ autocomplete .preview_undo_text_edit })
237
+ end
238
+
239
+ autocomplete .preview_undo_text_edit = require (' blink.cmp.accept.preview' )(selected_item )
224
240
autocomplete .preview_context_id = autocomplete .context .id
225
241
end )
226
242
end
0 commit comments