0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.1.1053: "nosort" enables fuzzy filtering even if "fuzzy" isn't in 'completeopt'

Problem:  "nosort" enables fuzzy filtering even if "fuzzy" isn't in
          'completeopt' (after v9.1.1049)
Solution: Only enable fuzzy filtering when "fuzzy" is in 'completeopt'.
          (zeertzjq)

closes: #16510

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2025-01-25 15:29:03 +01:00 committed by Christian Brabandt
parent 509a8d58f9
commit d65aa1bbdb
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 14 additions and 7 deletions

View File

@ -1264,8 +1264,8 @@ ins_compl_build_pum(void)
int max_fuzzy_score = 0; int max_fuzzy_score = 0;
unsigned int cur_cot_flags = get_cot_flags(); unsigned int cur_cot_flags = get_cot_flags();
int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0; int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0;
int fuzzy_nosort = (cur_cot_flags & COT_NOSORT) != 0; int fuzzy_filter = (cur_cot_flags & COT_FUZZY) != 0;
int fuzzy_filter = fuzzy_nosort || (cur_cot_flags & COT_FUZZY) != 0; int fuzzy_sort = fuzzy_filter && !(cur_cot_flags & COT_NOSORT);
compl_T *match_head = NULL; compl_T *match_head = NULL;
compl_T *match_tail = NULL; compl_T *match_tail = NULL;
compl_T *match_next = NULL; compl_T *match_next = NULL;
@ -1328,14 +1328,14 @@ ins_compl_build_pum(void)
shown_compl = compl; shown_compl = compl;
// Update the maximum fuzzy score and the shown match // Update the maximum fuzzy score and the shown match
// if the current item's score is higher // if the current item's score is higher
if (!fuzzy_nosort && compl->cp_score > max_fuzzy_score) if (fuzzy_sort && compl->cp_score > max_fuzzy_score)
{ {
did_find_shown_match = TRUE; did_find_shown_match = TRUE;
max_fuzzy_score = compl->cp_score; max_fuzzy_score = compl->cp_score;
if (!compl_no_select) if (!compl_no_select)
compl_shown_match = compl; compl_shown_match = compl;
} }
else if (fuzzy_nosort && i == 0 && !compl_no_select) else if (!fuzzy_sort && i == 0 && !compl_no_select)
compl_shown_match = shown_compl; compl_shown_match = shown_compl;
if (!shown_match_ok && compl == compl_shown_match && !compl_no_select) if (!shown_match_ok && compl == compl_shown_match && !compl_no_select)
@ -1392,7 +1392,7 @@ ins_compl_build_pum(void)
compl = match_next; compl = match_next;
} }
if (fuzzy_filter && !fuzzy_nosort && compl_leader.string != NULL && compl_leader.length > 0) if (fuzzy_sort && compl_leader.string != NULL && compl_leader.length > 0)
{ {
for (i = 0; i < compl_match_arraysize; i++) for (i = 0; i < compl_match_arraysize; i++)
compl_match_array[i].pum_idx = i; compl_match_array[i].pum_idx = i;

View File

@ -2857,8 +2857,8 @@ func Test_complete_fuzzy_match()
" test case for nosort option " test case for nosort option
set cot=menuone,menu,noinsert,fuzzy,nosort set cot=menuone,menu,noinsert,fuzzy,nosort
" fooBaz" should have a higher score when the leader is "fb". " "fooBaz" should have a higher score when the leader is "fb".
" With `nosort`, "foobar" should still be shown first in the popup menu. " With "nosort", "foobar" should still be shown first in the popup menu.
call feedkeys("S\<C-x>\<C-o>fb", 'tx') call feedkeys("S\<C-x>\<C-o>fb", 'tx')
call assert_equal('foobar', g:word) call assert_equal('foobar', g:word)
call feedkeys("S\<C-x>\<C-o>好", 'tx') call feedkeys("S\<C-x>\<C-o>好", 'tx')
@ -2870,6 +2870,11 @@ func Test_complete_fuzzy_match()
call feedkeys("S\<C-x>\<C-o>好\<C-N>", 'tx') call feedkeys("S\<C-x>\<C-o>好\<C-N>", 'tx')
call assert_equal('你好吗', g:word) call assert_equal('你好吗', g:word)
" "nosort" shouldn't enable fuzzy filtering when "fuzzy" isn't present.
set cot=menuone,noinsert,nosort
call feedkeys("S\<C-x>\<C-o>fooB\<C-Y>", 'tx')
call assert_equal('fooBaz', getline('.'))
" clean up " clean up
set omnifunc= set omnifunc=
bw! bw!

View File

@ -704,6 +704,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 */
/**/
1053,
/**/ /**/
1052, 1052,
/**/ /**/