Skip to content

Commit 0c0590d

Browse files
committed
patch 8.0.0250: virtcol() does not work well for multi-byte characters
Problem: When virtcol() gets a column that is not the first byte of a multi-byte character the result is unpredictable. (Christian Ludwig) Solution: Correct the column to the first byte of a multi-byte character. Change the utf-8 test to new style.
1 parent 4bc2f2e commit 0c0590d

8 files changed

Lines changed: 76 additions & 70 deletions

File tree

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,6 @@ test1 \
20582058
test_listlbr \
20592059
test_listlbr_utf8 \
20602060
test_search_mbyte \
2061-
test_utf8 \
20622061
test_wordcount \
20632062
test3 test4 test5 test6 test7 test8 test9 \
20642063
test11 test12 test14 test15 test17 test18 test19 \
@@ -2183,6 +2182,7 @@ test_arglist \
21832182
test_undo \
21842183
test_unlet \
21852184
test_usercommands \
2185+
test_utf8 \
21862186
test_viminfo \
21872187
test_viml \
21882188
test_visual \

src/charset.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,14 @@ getvcol(
12961296
if (pos->col == MAXCOL)
12971297
posptr = NULL; /* continue until the NUL */
12981298
else
1299+
{
12991300
posptr = ptr + pos->col;
1301+
#ifdef FEAT_MBYTE
1302+
if (has_mbyte)
1303+
/* always start on the first byte */
1304+
posptr -= (*mb_head_off)(line, posptr);
1305+
#endif
1306+
}
13001307

13011308
/*
13021309
* This function is used very often, do some speed optimizations.

src/testdir/Make_all.mak

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ SCRIPTS_ALL = \
8484
test_listchars.out \
8585
test_listlbr.out \
8686
test_search_mbyte.out \
87-
test_utf8.out \
8887
test_wordcount.out
8988

9089

src/testdir/test_alot_utf8.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ source test_expr_utf8.vim
99
source test_matchadd_conceal_utf8.vim
1010
source test_regexp_utf8.vim
1111
source test_source_utf8.vim
12+
source test_utf8.vim

src/testdir/test_utf8.in

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/testdir/test_utf8.ok

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/testdir/test_utf8.vim

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
" Tests for Unicode manipulations
2+
if !has('multi_byte')
3+
finish
4+
endif
5+
6+
7+
" Visual block Insert adjusts for multi-byte char
8+
func Test_visual_block_insert()
9+
new
10+
call setline(1, ["aaa", "あああ", "bbb"])
11+
exe ":norm! gg0l\<C-V>jjIx\<Esc>"
12+
call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$'))
13+
bwipeout!
14+
endfunc
15+
16+
" Test for built-in function strchars()
17+
func Test_strchars()
18+
let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
19+
let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]]
20+
for i in range(len(inp))
21+
call assert_equal(exp[i][0], strchars(inp[i]))
22+
call assert_equal(exp[i][1], strchars(inp[i], 0))
23+
call assert_equal(exp[i][2], strchars(inp[i], 1))
24+
endfor
25+
endfunc
26+
27+
" Test for customlist completion
28+
function! CustomComplete1(lead, line, pos)
29+
return ['', '']
30+
endfunction
31+
32+
function! CustomComplete2(lead, line, pos)
33+
return ['あたし', 'あたま', 'あたりめ']
34+
endfunction
35+
36+
function! CustomComplete3(lead, line, pos)
37+
return ['Nこ', 'Nん', 'Nぶ']
38+
endfunction
39+
40+
func Test_customlist_completion()
41+
command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo
42+
call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx')
43+
call assert_equal('"Test1 ', getreg(':'))
44+
45+
command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
46+
call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx')
47+
call assert_equal('"Test2 あた', getreg(':'))
48+
49+
command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo
50+
call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx')
51+
call assert_equal('"Test3 N', getreg(':'))
52+
53+
call garbagecollect(1)
54+
endfunc
55+
56+
" Yank one 3 byte character and check the mark columns.
57+
func Test_getvcol()
58+
new
59+
call setline(1, "x\u2500x")
60+
normal 0lvy
61+
call assert_equal(2, col("'["))
62+
call assert_equal(4, col("']"))
63+
call assert_equal(2, virtcol("'["))
64+
call assert_equal(2, virtcol("']"))
65+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
250,
767769
/**/
768770
249,
769771
/**/

0 commit comments

Comments
 (0)