Skip to content

Commit f247402

Browse files
zeertzjqglepnir
andauthored
vim-patch:9.1.1107: cannot loop through completion menu with fuzzy (neovim#32438)
Problem: cannot loop through completion menu with fuzzy and nosort in 'completeopt' (Tomasz N) Solution: Reset cur to zero and update compl_shown_match when 'completeopt' contains "nosort" but not "noselect" (glepnir) fixes: vim/vim#16624 closes: vim/vim#16629 vim/vim@c0b7ca4 Co-authored-by: glepnir <[email protected]>
1 parent 478c71f commit f247402

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/nvim/insexpand.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,8 +1295,6 @@ static int ins_compl_build_pum(void)
12951295
if (!compl_no_select) {
12961296
compl_shown_match = comp;
12971297
}
1298-
} else if (!fuzzy_sort && i == 0 && !compl_no_select) {
1299-
compl_shown_match = shown_compl;
13001298
}
13011299
if (!shown_match_ok && comp == compl_shown_match && !compl_no_select) {
13021300
cur = i;
@@ -1327,6 +1325,12 @@ static int ins_compl_build_pum(void)
13271325
return -1;
13281326
}
13291327

1328+
if (fuzzy_filter && !fuzzy_sort && !compl_no_select && !shown_match_ok) {
1329+
compl_shown_match = shown_compl;
1330+
shown_match_ok = true;
1331+
cur = 0;
1332+
}
1333+
13301334
assert(compl_match_arraysize >= 0);
13311335
compl_match_array = xcalloc((size_t)compl_match_arraysize, sizeof(pumitem_T));
13321336

test/old/testdir/test_ins_complete.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,8 @@ func Test_complete_fuzzy_match()
27672767
func OnPumChange()
27682768
let g:item = get(v:event, 'completed_item', {})
27692769
let g:word = get(g:item, 'word', v:null)
2770+
let g:abbr = get(g:item, 'abbr', v:null)
2771+
let g:selected = get(complete_info(['selected']), 'selected')
27702772
endfunction
27712773

27722774
augroup AAAAA_Group
@@ -2857,6 +2859,20 @@ func Test_complete_fuzzy_match()
28572859
call feedkeys("S\<C-x>\<C-o>fooB\<C-Y>", 'tx')
28582860
call assert_equal('fooBaz', getline('.'))
28592861

2862+
set cot=menuone,fuzzy,nosort
2863+
func CompAnother()
2864+
call complete(col('.'), [#{word: "do" }, #{word: "echo"}, #{word: "for (${1:expr1}, ${2:expr2}, ${3:expr3}) {\n\t$0\n}", abbr: "for" }, #{word: "foo"}])
2865+
return ''
2866+
endfunc
2867+
call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>", 'tx')
2868+
call assert_equal("for", g:abbr)
2869+
call assert_equal(2, g:selected)
2870+
2871+
set cot+=noinsert
2872+
call feedkeys("i\<C-R>=CompAnother()\<CR>f", 'tx')
2873+
call assert_equal("for", g:abbr)
2874+
call assert_equal(2, g:selected)
2875+
28602876
" clean up
28612877
set omnifunc=
28622878
bw!
@@ -2866,8 +2882,11 @@ func Test_complete_fuzzy_match()
28662882
delfunc OnPumChange
28672883
delfunc Omni_test
28682884
delfunc Comp
2885+
delfunc CompAnother
28692886
unlet g:item
28702887
unlet g:word
2888+
unlet g:selected
2889+
unlet g:abbr
28712890
endfunc
28722891

28732892
" Check that tie breaking is stable for completeopt+=fuzzy (which should

0 commit comments

Comments
 (0)