@@ -191,7 +191,7 @@ function! s:HideDuringCompletion() abort
191191endfunction
192192
193193function ! s: SuggestionTextWithAdjustments () abort
194- let empty = [' ' , 0 , 0 , {}]
194+ let empty = [' ' , 0 , ' ' , {}]
195195 try
196196 if mode () !~# ' ^[iR]' || (s: HideDuringCompletion () && pumvisible ()) || ! exists (' b:_copilot.suggestions' )
197197 return empty
@@ -215,10 +215,10 @@ function! s:SuggestionTextWithAdjustments() abort
215215 let leading = strpart (matchstr (choice_text, ' ^\s\+' ), 0 , len (typed))
216216 let unindented = strpart (choice_text, len (leading))
217217 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]
219219 endif
220220 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]
222222 endif
223223 catch
224224 call copilot#logger#Exception ()
@@ -290,7 +290,8 @@ function! copilot#GetDisplayedSuggestion() abort
290290 \ ' item' : item,
291291 \ ' text' : text,
292292 \ ' outdentSize' : outdent,
293- \ ' deleteSize' : delete }
293+ \ ' deleteSize' : strchars (delete ),
294+ \ ' deleteChars' : delete }
294295endfunction
295296
296297function ! s: ClearPreview () abort
@@ -304,7 +305,8 @@ endfunction
304305
305306function ! s: UpdatePreview () abort
306307 try
307- let [text, outdent, delete , item] = s: SuggestionTextWithAdjustments ()
308+ let [text, outdent, delete_chars, item] = s: SuggestionTextWithAdjustments ()
309+ let delete = strchars (delete_chars)
308310 let text = split (text, " \r \n \\ =\\ |\n " , 1 )
309311 if empty (text[-1 ])
310312 call remove (text, -1 )
@@ -489,6 +491,13 @@ function! copilot#Accept(...) abort
489491 if empty (text)
490492 let text = s .text
491493 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
492501 if text == # s .text && has_key (s .item, ' command' )
493502 call copilot#Request (' workspace/executeCommand' , s .item.command )
494503 else
@@ -500,7 +509,7 @@ function! copilot#Accept(...) abort
500509 call s: ClearPreview ()
501510 let s: suggestion_text = text
502511 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) ) .
504513 \ recall . " copilot#TextQueuedForInsertion()\<CR> " . (a: 0 > 1 ? ' ' : " \<End> " )
505514 endif
506515 let default = get (g: , ' copilot_tab_fallback' , pumvisible () ? " \<C-N> " : " \t " )
0 commit comments