Skip to content

Commit 057ea12

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1931: completion: wrong item selected with fuzzy and noinsert
Problem: completion: wrong item selected with fuzzy and noinsert (Evgeni Chasnovski) Solution: Reset selected item after fuzzy sort (Girish Palya) fixes: #18802 closes: #18816 Signed-off-by: Girish Palya <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 33fbfe0 commit 057ea12

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/insexpand.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,18 +2480,20 @@ ins_compl_fuzzy_sort(void)
24802480
{
24812481
int cur_cot_flags = get_cot_flags();
24822482

2483-
// set the fuzzy score in cp_score
2483+
// Set the fuzzy score in cp_score and sort
24842484
set_fuzzy_score();
2485-
// Sort the matches linked list based on fuzzy score
24862485
if (!(cur_cot_flags & COT_NOSORT))
24872486
{
24882487
sort_compl_match_list(cp_compare_fuzzy);
2489-
if ((cur_cot_flags & (COT_NOINSERT | COT_NOSELECT)) == COT_NOINSERT
2490-
&& compl_first_match)
2491-
{
2492-
compl_shown_match = compl_first_match;
2493-
if (compl_shows_dir_forward() && !compl_autocomplete)
2494-
compl_shown_match = compl_first_match->cp_next;
2488+
// Reset the shown item since sorting reorders items
2489+
if ((cur_cot_flags & (COT_NOINSERT | COT_NOSELECT)) == COT_NOINSERT)
2490+
{
2491+
int none_selected = compl_shown_match == (compl_shows_dir_forward()
2492+
? compl_first_match : compl_first_match->cp_prev);
2493+
if (!none_selected)
2494+
compl_shown_match
2495+
= (!compl_autocomplete && compl_shows_dir_forward())
2496+
? compl_first_match->cp_next : compl_first_match;
24952497
}
24962498
}
24972499
}

src/testdir/test_ins_complete.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,15 @@ func Test_complete_opt_fuzzy()
35933593
call feedkeys("Gof\<C-N>\<C-R>=PrintMenuWords()\<CR>\<Esc>0", 'tx')
35943594
call assert_equal('f{''items'': [''func1'', ''func2'', ''xfunc'']}', getline('.'))
35953595

3596+
" Issue #18802: Reset selected item after fuzzy sort
3597+
%d
3598+
call setline(1, ['aa', 'aaa', 'aaaa'])
3599+
set completeopt=menuone,noinsert,fuzzy
3600+
call feedkeys("Goa\<C-N>\<C-Y>\<Esc>", 'tx')
3601+
call assert_equal('aa', getline('.'))
3602+
call feedkeys("Goa\<C-P>\<C-Y>\<Esc>", 'tx')
3603+
call assert_equal('aaaa', getline('.'))
3604+
35963605
" clean up
35973606
set omnifunc=
35983607
bw!

src/version.c

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

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1931,
732734
/**/
733735
1930,
734736
/**/

0 commit comments

Comments
 (0)