fix: vim plugin inline completion display error if starts with newline. (#216)

improve-workflow
Zhiming Ma 2023-06-08 00:12:09 +08:00 committed by GitHub
parent c82cc38e9d
commit 0528c36bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -397,6 +397,13 @@ function! tabby#Show()
return return
endif endif
let lines = split(choice.text, "\n") let lines = split(choice.text, "\n")
" split will not give an empty line if text starts with "\n" or ends with "\n"
if choice.text[0] == "\n"
call insert(lines, '')
endif
if choice.text[-1] == "\n"
call add(lines, '')
endif
call tabby#virtual_text#Show(lines) call tabby#virtual_text#Show(lines)
let s:shown_lines = lines let s:shown_lines = lines
call s:PostEvent('view') call s:PostEvent('view')

View File

@ -35,14 +35,15 @@ function! tabby#virtual_text#Show(lines)
endif endif
if s:vim if s:vim
" virtual text requires 9.0.0534 " virtual text requires 9.0.0534
" append line with a space to avoid empty line, which will result in unexpected behavior
call prop_add(line('.'), col('.'), #{ call prop_add(line('.'), col('.'), #{
\ type: s:prop_type, \ type: s:prop_type,
\ text: a:lines[0], \ text: a:lines[0] . ' ',
\ }) \ })
for line in a:lines[1:] for line in a:lines[1:]
call prop_add(line('.'), 0, #{ call prop_add(line('.'), 0, #{
\ type: s:prop_type, \ type: s:prop_type,
\ text: line, \ text: line . ' ',
\ text_align: 'below', \ text_align: 'below',
\ }) \ })
endfor endfor