Skip to content

Commit 4f8fa16

Browse files
committed
patch 7.4.926
Problem: Completing the longest match doesn't work properly with multi-byte characters. Solution: When using multi-byte characters use another way to find the longest match. (Hirohito Higashi)
1 parent a0ed84a commit 4f8fa16

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/ex_getln.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3691,20 +3691,37 @@ ExpandOne(xp, str, orig, options, mode)
36913691
/* Find longest common part */
36923692
if (mode == WILD_LONGEST && xp->xp_numfiles > 0)
36933693
{
3694-
for (len = 0; xp->xp_files[0][len]; ++len)
3694+
int mb_len = 1;
3695+
int c0, ci;
3696+
3697+
for (len = 0; xp->xp_files[0][len]; len += mb_len)
36953698
{
3696-
for (i = 0; i < xp->xp_numfiles; ++i)
3699+
#ifdef FEAT_MBYTE
3700+
if (has_mbyte)
36973701
{
3702+
mb_len = (*mb_ptr2len)(&xp->xp_files[0][len]);
3703+
c0 =(* mb_ptr2char)(&xp->xp_files[0][len]);
3704+
}
3705+
else
3706+
#endif
3707+
c0 = xp->xp_files[i][len];
3708+
for (i = 1; i < xp->xp_numfiles; ++i)
3709+
{
3710+
#ifdef FEAT_MBYTE
3711+
if (has_mbyte)
3712+
ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
3713+
else
3714+
#endif
3715+
ci = xp->xp_files[i][len];
36983716
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
36993717
|| xp->xp_context == EXPAND_FILES
37003718
|| xp->xp_context == EXPAND_SHELLCMD
37013719
|| xp->xp_context == EXPAND_BUFFERS))
37023720
{
3703-
if (TOLOWER_LOC(xp->xp_files[i][len]) !=
3704-
TOLOWER_LOC(xp->xp_files[0][len]))
3721+
if (MB_TOLOWER(c0) != MB_TOLOWER(ci))
37053722
break;
37063723
}
3707-
else if (xp->xp_files[i][len] != xp->xp_files[0][len])
3724+
else if (c0 != ci)
37083725
break;
37093726
}
37103727
if (i < xp->xp_numfiles)
@@ -3714,6 +3731,7 @@ ExpandOne(xp, str, orig, options, mode)
37143731
break;
37153732
}
37163733
}
3734+
37173735
ss = alloc((unsigned)len + 1);
37183736
if (ss)
37193737
vim_strncpy(ss, xp->xp_files[0], (size_t)len);

src/testdir/test_utf8.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ STARTTEST
1717
: $put=strchars(str, 0)
1818
: $put=strchars(str, 1)
1919
:endfor
20+
:" Test for customlist completion
21+
:function! CustomComplete1(lead, line, pos)
22+
: return ['', '']
23+
:endfunction
24+
:command -nargs=1 -complete=customlist,CustomComplete1 Test1 :
25+
:call feedkeys(":Test1 \<C-L>'\<C-B>$put='\<CR>", 't')
26+
:
27+
:function! CustomComplete2(lead, line, pos)
28+
: return ['あたし', 'あたま', 'あたりめ']
29+
:endfunction
30+
:command -nargs=1 -complete=customlist,CustomComplete2 Test2 :
31+
:call feedkeys(":Test2 \<C-L>'\<C-B>$put='\<CR>", 't')
32+
:
33+
:function! CustomComplete3(lead, line, pos)
34+
: return ['Nこ', 'Nん', 'Nぶ']
35+
:endfunction
36+
:command -nargs=1 -complete=customlist,CustomComplete3 Test3 :
37+
:call feedkeys(":Test3 \<C-L>'\<C-B>$put='\<CR>", 't')
38+
:
2039
:call garbagecollect(1)
2140
:/^start:/,$wq! test.out
2241
ENDTEST

src/testdir/test_utf8.ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ bxbb
1717
1
1818
1
1919
1
20+
Test1
21+
Test2 あた
22+
Test3 N

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
926,
744746
/**/
745747
925,
746748
/**/

0 commit comments

Comments
 (0)