fix(vim): multibytes characters counting. (#345)

release-0.0
Zhiming Ma 2023-08-09 17:42:57 +08:00 committed by GitHub
parent dbc89831b1
commit d89d5aeef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -449,8 +449,7 @@ function! tabby#Accept(...)
let s:text_to_insert = lines[0]
let insertion = "\<C-R>\<C-O>=tabby#ConsumeInsertion()\<CR>"
else
let current_line = getbufline('%', line('.'), line('.'))[0]
let suffix_chars_to_replace = len(current_line) - col('.') + 1
let suffix_chars_to_replace = strchars(getline(line('.'))[col('.') - 1:])
let s:text_to_insert = join(lines, "\n")
let insertion = repeat("\<Del>", suffix_chars_to_replace) . "\<C-R>\<C-O>=tabby#ConsumeInsertion()\<CR>\<End>"
endif
@ -550,12 +549,22 @@ function! s:CreateCompletionRequest()
\ filepath: expand('%:p'),
\ language: s:GetLanguage(),
\ text: join(getbufline('%', 1, '$'), "\n"),
\ position: line2byte(line('.')) + col('.') - 2,
\ position: s:CountCharsToCursor(),
\ maxPrefixLines: g:tabby_max_prefix_lines,
\ maxSuffixLines: g:tabby_max_suffix_lines,
\ }
endfunction
function! s:CountCharsToCursor()
let lines = getline(1, line('.') - 1)
if col('.') > 1
let lines += [getline(line('.'))[:col('.') - 2]]
else
let lines += ['']
endif
return strchars(join(lines, "\n"))
endfunction
function! s:GetLanguage()
let filetype = getbufvar('%', '&filetype')
if has_key(g:tabby_filetype_to_languages, filetype)