Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95267b6

Browse files
zeertzjqgirishji
andauthored
vim-patch:9.1.1769: completion: "preinsert" insert wrong word with 'smartcase' and 'autocomplete' (#35834)
Problem: completion: "preinsert" insert wrong word with 'smartcase' and 'autocomplete' Solution: Add compare completed item with the leader (Girish Palya) closes: vim/vim#18313 vim/vim@a8f7957 Co-authored-by: Girish Palya <[email protected]>
1 parent b443a3c commit 95267b6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/nvim/insexpand.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5069,10 +5069,11 @@ static char *find_common_prefix(size_t *prefix_len, bool curbuf_only)
50695069

50705070
if (!match_limit_exceeded
50715071
&& (!curbuf_only || cpt_sources_array[cur_source].cs_flag == '.')) {
5072-
if (first == NULL) {
5072+
if (first == NULL && strncmp(ins_compl_leader(), compl->cp_str.data,
5073+
ins_compl_leader_len()) == 0) {
50735074
first = compl->cp_str.data;
50745075
len = (int)strlen(first);
5075-
} else {
5076+
} else if (first != NULL) {
50765077
int j = 0; // count in bytes
50775078
char *s1 = first;
50785079
char *s2 = compl->cp_str.data;
@@ -5100,7 +5101,7 @@ static char *find_common_prefix(size_t *prefix_len, bool curbuf_only)
51005101

51015102
xfree(match_count);
51025103

5103-
if (len > get_compl_len()) {
5104+
if (len > (int)ins_compl_leader_len()) {
51045105
*prefix_len = (size_t)len;
51055106
return first;
51065107
}

test/old/testdir/test_ins_complete.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,7 +5771,18 @@ func Test_autocomplete_completeopt_preinsert()
57715771
call DoTest("f", 'f', 2)
57725772
set cot-=fuzzy
57735773

5774+
" leader should match prefix of inserted word
5775+
%delete
5776+
set smartcase ignorecase
5777+
call setline(1, ["FOO"])
5778+
call feedkeys($"Gof\<F5>\<Esc>", 'tx')
5779+
call assert_equal('f', g:line)
5780+
call feedkeys($"SF\<F5>\<Esc>", 'tx')
5781+
call assert_equal('FOO', g:line)
5782+
set smartcase& ignorecase&
5783+
57745784
" Verify that redo (dot) works
5785+
%delete
57755786
call setline(1, ["foobar", "foozbar", "foobaz", "changed", "change"])
57765787
call feedkeys($"/foo\<CR>", 'tx')
57775788
call feedkeys($"cwch\<C-N>\<Esc>n.n.", 'tx')

0 commit comments

Comments
 (0)