Skip to content

Commit

Permalink
Fix offset calculation for multi-byte characters
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed May 8, 2015
1 parent 7c2349c commit bc7d393
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions autoload/after_object.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function! s:after(str, cnt, vis, bw)
let len = 0
let idx = 0
for part in parts[0 : (a:bw ? -2 : -3)]
let len += len(part)
let len += strchars(part)
if len > col - 1
break
endif
Expand All @@ -53,10 +53,10 @@ function! s:after(str, cnt, vis, bw)
if a:bw
let idx = max([idx - 2, 0])
endif
let col = len(join(parts[0 : idx], '')) + (i > 1 && a:cnt > 1)
let col = strchars(join(parts[0 : idx], '')) + (i > 1 && a:cnt > 1)
endfor

let rest = line[col : -1]
let rest = substitute(line, '^.\{'.col.'}', '', '')
if empty(rest)
throw 'exit'
else
Expand Down
13 changes: 13 additions & 0 deletions test/after_object.vader
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,16 @@ Do:

Expect:
abc =

Given (Multi-byte characters):
___가나다: foobar
___가나다: ___라마바: foobar

Do:
ca:hello\<esc>
jva:a:chello\<esc>

Expect:
___가나다: hello
___가나다: ___라마바: hello

0 comments on commit bc7d393

Please sign in to comment.