vim-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)

4f8fa1633c
This commit is contained in:
watiko 2016-02-15 23:43:27 +09:00
parent 7609a96a35
commit 3680332325
3 changed files with 57 additions and 9 deletions

View File

@ -2957,21 +2957,38 @@ ExpandOne (
} }
} }
/* Find longest common part */ // Find longest common part
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
size_t len; size_t len;
for (len = 0; xp->xp_files[0][len]; ++len) { size_t mb_len = 1;
for (i = 0; i < xp->xp_numfiles; ++i) { int c0;
int ci;
for (len = 0; xp->xp_files[0][len]; len += mb_len) {
if (has_mbyte) {
mb_len = (* mb_ptr2len)(&xp->xp_files[0][len]);
c0 = (* mb_ptr2char)(&xp->xp_files[0][len]);
} else {
c0 = xp->xp_files[i][len];
}
for (i = 1; i < xp->xp_numfiles; ++i) {
if (has_mbyte) {
ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
} else {
ci = xp->xp_files[i][len];
}
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|| xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_SHELLCMD || xp->xp_context == EXPAND_SHELLCMD
|| xp->xp_context == EXPAND_BUFFERS)) { || xp->xp_context == EXPAND_BUFFERS)) {
if (TOLOWER_LOC(xp->xp_files[i][len]) != if (vim_tolower(c0) != vim_tolower(ci)) {
TOLOWER_LOC(xp->xp_files[0][len]))
break; break;
} else if (xp->xp_files[i][len] != xp->xp_files[0][len]) }
} else if (c0 != ci) {
break; break;
} }
}
if (i < xp->xp_numfiles) { if (i < xp->xp_numfiles) {
if (!(options & WILD_NO_BEEP)) { if (!(options & WILD_NO_BEEP)) {
vim_beep(BO_WILD); vim_beep(BO_WILD);
@ -2979,8 +2996,9 @@ ExpandOne (
break; break;
} }
} }
ss = (char_u *)xstrndup((char *)xp->xp_files[0], len); ss = (char_u *)xstrndup((char *)xp->xp_files[0], len);
findex = -1; /* next p_wc gets first one */ findex = -1; // next p_wc gets first one
} }
// Concatenate all matching names // Concatenate all matching names

View File

@ -362,7 +362,7 @@ static int included_patches[] = {
929, 929,
// 928 NA // 928 NA
// 927 NA // 927 NA
// 926, 926,
// 925, // 925,
// 924 NA // 924 NA
// 923 NA // 923 NA

View File

@ -4,9 +4,10 @@ local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect local execute, expect = helpers.execute, helpers.expect
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local source = helpers.source
describe('utf8', function() describe('utf8', function()
setup(clear) before_each(clear)
it('is working', function() it('is working', function()
insert('start:') insert('start:')
@ -50,4 +51,33 @@ describe('utf8', function()
eq(1, eval('strchars("\\u20dd", 0)')) eq(1, eval('strchars("\\u20dd", 0)'))
eq(1, eval('strchars("\\u20dd", 1)')) eq(1, eval('strchars("\\u20dd", 1)'))
end) end)
it('customlist completion', function()
source([[
function! CustomComplete1(lead, line, pos)
return ['', '']
endfunction
command -nargs=1 -complete=customlist,CustomComplete1 Test1 :]])
feed(":Test1 <C-L>'<C-B>$put='<CR>")
source([[
function! CustomComplete2(lead, line, pos)
return ['あたし', 'あたま', 'あたりめ']
endfunction
command -nargs=1 -complete=customlist,CustomComplete2 Test2 :]])
feed(":Test2 <C-L>'<C-B>$put='<CR>")
source([[
function! CustomComplete3(lead, line, pos)
return ['Nこ', 'Nん', 'Nぶ']
endfunction
command -nargs=1 -complete=customlist,CustomComplete3 Test3 :]])
feed(":Test3 <C-L>'<C-B>$put='<CR>")
expect([[
Test1
Test2
Test3 N]])
end)
end) end)