@@ -191,7 +191,7 @@ function! s:HideDuringCompletion() abort
191
191
endfunction
192
192
193
193
function ! s: SuggestionTextWithAdjustments () abort
194
- let empty = [' ' , 0 , 0 , {}]
194
+ let empty = [' ' , 0 , ' ' , {}]
195
195
try
196
196
if mode () !~# ' ^[iR]' || (s: HideDuringCompletion () && pumvisible ()) || ! exists (' b:_copilot.suggestions' )
197
197
return empty
@@ -215,10 +215,10 @@ function! s:SuggestionTextWithAdjustments() abort
215
215
let leading = strpart (matchstr (choice_text, ' ^\s\+' ), 0 , len (typed))
216
216
let unindented = strpart (choice_text, len (leading))
217
217
if strpart (typed, 0 , len (leading)) == # leading && unindented !=# delete
218
- return [unindented, len (typed) - len (leading), strchars ( delete ) , choice]
218
+ return [unindented, len (typed) - len (leading), delete , choice]
219
219
endif
220
220
elseif typed == # strpart (choice_text, 0 , offset)
221
- return [strpart (choice_text, offset), 0 , strchars ( delete ) , choice]
221
+ return [strpart (choice_text, offset), 0 , delete , choice]
222
222
endif
223
223
catch
224
224
call copilot#logger#Exception ()
@@ -290,7 +290,8 @@ function! copilot#GetDisplayedSuggestion() abort
290
290
\ ' item' : item,
291
291
\ ' text' : text,
292
292
\ ' outdentSize' : outdent,
293
- \ ' deleteSize' : delete }
293
+ \ ' deleteSize' : strchars (delete ),
294
+ \ ' deleteChars' : delete }
294
295
endfunction
295
296
296
297
function ! s: ClearPreview () abort
@@ -304,7 +305,8 @@ endfunction
304
305
305
306
function ! s: UpdatePreview () abort
306
307
try
307
- let [text, outdent, delete , item] = s: SuggestionTextWithAdjustments ()
308
+ let [text, outdent, delete_chars, item] = s: SuggestionTextWithAdjustments ()
309
+ let delete = strchars (delete_chars)
308
310
let text = split (text, " \r \n \\ =\\ |\n " , 1 )
309
311
if empty (text[-1 ])
310
312
call remove (text, -1 )
@@ -489,6 +491,13 @@ function! copilot#Accept(...) abort
489
491
if empty (text)
490
492
let text = s .text
491
493
endif
494
+ let delete_chars = s .deleteChars
495
+ let leftover = strpart (s .text, strlen (text))
496
+ let idx = strridx (leftover, matchstr (delete_chars, ' .$' ))
497
+ while ! empty (delete_chars) && idx != -1
498
+ let delete_chars = substitute (delete_chars, ' .$' , ' ' , ' ' )
499
+ let idx = strridx (leftover, matchstr (delete_chars, ' .$' ), idx - 1 )
500
+ endwhile
492
501
if text == # s .text && has_key (s .item, ' command' )
493
502
call copilot#Request (' workspace/executeCommand' , s .item.command )
494
503
else
@@ -500,7 +509,7 @@ function! copilot#Accept(...) abort
500
509
call s: ClearPreview ()
501
510
let s: suggestion_text = text
502
511
let recall = text = ~# " \n " ? " \<C-R>\<C-O> =" : " \<C-R>\<C-R> ="
503
- return repeat (" \<Left>\<Del> " , s .outdentSize) . repeat (" \<Del> " , s .deleteSize ) .
512
+ return repeat (" \<Left>\<Del> " , s .outdentSize) . repeat (" \<Del> " , strchars (delete_chars) ) .
504
513
\ recall . " copilot#TextQueuedForInsertion()\<CR> " . (a: 0 > 1 ? ' ' : " \<End> " )
505
514
endif
506
515
let default = get (g: , ' copilot_tab_fallback' , pumvisible () ? " \<C-N> " : " \t " )
0 commit comments