diff --git a/clients/vim/autoload/tabby.vim b/clients/vim/autoload/tabby.vim index 9663264..efa21c5 100644 --- a/clients/vim/autoload/tabby.vim +++ b/clients/vim/autoload/tabby.vim @@ -449,8 +449,7 @@ function! tabby#Accept(...) let s:text_to_insert = lines[0] let insertion = "\\=tabby#ConsumeInsertion()\" 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("\", suffix_chars_to_replace) . "\\=tabby#ConsumeInsertion()\\" 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)