@@ -353,7 +353,26 @@ function! s:UpdatePreview() abort
353353 let data.hl_mode = ' combine'
354354 call nvim_buf_set_extmark (0 , copilot#NvimNs (), line (' .' )-1 , col (' .' )-1 , data)
355355 elseif s: has_vim_ghost_text
356- call prop_add (line (' .' ), col (' .' ), {' type' : s: hlgroup , ' text' : text[0 ]})
356+ let new_suffix = text[0 ]
357+ let current_suffix = getline (' .' )[col (' .' ) - 1 :]
358+ let inset = ' '
359+ while delete > 0 && ! empty (new_suffix)
360+ let last_char = matchstr (new_suffix, ' .$' )
361+ let new_suffix = matchstr (new_suffix, ' ^.\{-\}\ze.$' )
362+ if last_char == # matchstr (current_suffix, ' .$' )
363+ if ! empty (inset)
364+ call prop_add (line (' .' ), col (' .' ) + len (current_suffix), {' type' : s: hlgroup , ' text' : inset})
365+ let inset = ' '
366+ endif
367+ let current_suffix = matchstr (current_suffix, ' ^.\{-\}\ze.$' )
368+ let delete -= 1
369+ else
370+ let inset = last_char . inset
371+ endif
372+ endwhile
373+ if ! empty (new_suffix . inset)
374+ call prop_add (line (' .' ), col (' .' ), {' type' : s: hlgroup , ' text' : new_suffix . inset})
375+ endif
357376 for line in text[1 :]
358377 call prop_add (line (' .' ), 0 , {' type' : s: hlgroup , ' text_align' : ' below' , ' text' : line })
359378 endfor
0 commit comments