File tree 3 files changed +11
-10
lines changed
3 files changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
--- @param item blink.cmp.CompletionItem
2
- local function preview (item )
2
+ local function preview (item , previous_text_edit )
3
3
local text_edits_lib = require (' blink.cmp.accept.text-edits' )
4
4
local text_edit = text_edits_lib .get_from_item (item )
5
5
@@ -9,6 +9,8 @@ local function preview(item)
9
9
text_edit .newText = expanded_snippet and tostring (expanded_snippet ) or text_edit .newText
10
10
end
11
11
12
+ if previous_text_edit ~= nil then text_edit .range = text_edits_lib .get_undo_text_edit_range (previous_text_edit ) end
13
+
12
14
text_edits_lib .apply_text_edits (item .client_id , { text_edit })
13
15
vim .api .nvim_win_set_cursor (0 , {
14
16
text_edit .range .start .line + 1 ,
Original file line number Diff line number Diff line change @@ -28,16 +28,16 @@ function text_edits.apply_text_edits(client_id, edits)
28
28
end
29
29
30
30
--- @param text_edit lsp.TextEdit
31
- function text_edits .undo_text_edit (text_edit )
31
+ function text_edits .get_undo_text_edit_range (text_edit )
32
32
text_edit = vim .deepcopy (text_edit )
33
33
local lines = vim .split (text_edit .newText , ' \n ' )
34
- local range = text_edit . range
34
+ local last_line_len = lines [ # lines ] and # lines [ # lines ] or 0
35
35
36
+ local range = text_edit .range
36
37
range [' end' ].line = range .start .line + # lines - 1
37
- range [' end' ].character = lines [# lines ] and # lines [# lines ] or 0
38
- text_edit .newText = ' '
38
+ range [' end' ].character = # lines > 1 and last_line_len or range .start .character + last_line_len
39
39
40
- vim . lsp . util . apply_text_edits ({ text_edit }, vim . api . nvim_get_current_buf (), ' utf-16 ' )
40
+ return range
41
41
end
42
42
43
43
--- @param item blink.cmp.CompletionItem
Original file line number Diff line number Diff line change @@ -185,10 +185,9 @@ local function select(line, skip_auto_insert)
185
185
-- when auto_insert is enabled, we immediately apply the text edit
186
186
if config .windows .autocomplete .selection == ' auto_insert' and selected_item ~= nil and not skip_auto_insert then
187
187
require (' blink.cmp.trigger.completion' ).suppress_events_for_callback (function ()
188
- if autocomplete .preview_text_edit ~= nil and autocomplete .preview_context_id == autocomplete .context .id then
189
- text_edits_lib .undo_text_edit (autocomplete .preview_text_edit )
190
- end
191
- autocomplete .preview_text_edit = require (' blink.cmp.accept.preview' )(selected_item )
188
+ if autocomplete .preview_context_id ~= autocomplete .context .id then autocomplete .preview_text_edit = nil end
189
+ autocomplete .preview_text_edit =
190
+ require (' blink.cmp.accept.preview' )(selected_item , autocomplete .preview_text_edit )
192
191
autocomplete .preview_context_id = autocomplete .context .id
193
192
end )
194
193
end
You can’t perform that action at this time.
0 commit comments