Skip to content

Commit

Permalink
suggest/utils: fix autocomplete for fields
Browse files Browse the repository at this point in the history
For fields completion like:

    A.|
      ^ cursor

Previously the plugin would tell the completion handler that the cursor
is at:

    A.
     ^

which is not a `keyword`, thus the completion won't be triggered.

This commit fixes the issue by adjusting the starting position variable
instead of the cursor position.
  • Loading branch information
alaviss committed Apr 3, 2021
1 parent 1a6473d commit c570e52
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions autoload/nim/suggest/utils.vim
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ endfunction
function! nim#suggest#utils#FindIdentifierStart() abort
let line = getline('.')
let start = col('.')
if mode() is# 'i'
" when in insert mode, the cursor will be placed at the next character,
" so we reduce it to get the right position.
let start -= 1
endif
" the cursor position starts from 1, but string starts from 0.
let result = start - 1
if mode() is# 'i'
" when in insert mode, the cursor will be placed on the next (non-existent)
" character, so we have to reduce the starting index by one.
let result -= 1
endif
while result >= 0 && line[result] =~ '\k'
let result -= 1
endwhile
Expand Down

0 comments on commit c570e52

Please sign in to comment.