patch 9.1.1918: completion: crash with fuzzy completion

Problem:  completion: crash with fuzzy completion
          (Christian Brabandt)
Solution: When completion candidates are gathered from a different
          window, and when completing `<c-p>`, linked list should be
          sorted only after all items are collected (Girish Palya).

fixes: #18752
closes: #18756

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Girish Palya
2025-11-16 18:30:42 +00:00
committed by Christian Brabandt
parent 4b4a893614
commit 6437997d83
3 changed files with 25 additions and 4 deletions

View File

@@ -5710,11 +5710,14 @@ ins_compl_get_exp(pos_T *ini)
} }
may_trigger_modechanged(); may_trigger_modechanged();
if (is_nearest_active() && !ins_compl_has_preinsert()) if (match_count > 0)
sort_compl_match_list(cp_compare_nearest); {
if (is_nearest_active() && !ins_compl_has_preinsert())
sort_compl_match_list(cp_compare_nearest);
if ((get_cot_flags() & COT_FUZZY) && ins_compl_leader_len() > 0) if ((get_cot_flags() & COT_FUZZY) && ins_compl_leader_len() > 0)
ins_compl_fuzzy_sort(); ins_compl_fuzzy_sort();
}
return match_count; return match_count;
} }

View File

@@ -3705,6 +3705,22 @@ func Test_complete_fuzzy_collect()
set completeopt& cfc& cpt& set completeopt& cfc& cpt&
endfunc endfunc
" Issue #18752
func Test_complete_fuzzy_collect_multiwin()
new
set completefuzzycollect=keyword,files,whole_line
set completeopt=fuzzy
vnew
call setline(1, ["completeness,", "compatibility", "Composite", "Omnipotent"])
wincmd p
call feedkeys("Somp\<C-P>\<Esc>0", 'tx!')
call assert_equal('Omnipotent', getline('.'))
bw!
set completeopt& cfc&
endfunc
func Test_cfc_with_longest() func Test_cfc_with_longest()
new new
set completefuzzycollect=keyword,files,whole_line set completefuzzycollect=keyword,files,whole_line

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1918,
/**/ /**/
1917, 1917,
/**/ /**/