summaryrefslogtreecommitdiffstats
path: root/src/insexpand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/insexpand.c')
-rw-r--r--src/insexpand.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/insexpand.c b/src/insexpand.c
index 74be94cf4b..fafa7a2f0d 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -1203,11 +1203,13 @@ trigger_complete_changed_event(int cur)
* pumitem qsort compare func
*/
static int
-ins_compl_fuzzy_sort(const void *a, const void *b)
+ins_compl_fuzzy_cmp(const void *a, const void *b)
{
const int sa = (*(pumitem_T *)a).pum_score;
const int sb = (*(pumitem_T *)b).pum_score;
- return sa == sb ? 0 : sa < sb ? 1 : -1;
+ const int ia = (*(pumitem_T *)a).pum_idx;
+ const int ib = (*(pumitem_T *)b).pum_idx;
+ return sa == sb ? (ia == ib ? 0 : (ia < ib ? -1 : 1)) : (sa < sb ? 1 : -1);
}
/*
@@ -1355,8 +1357,13 @@ ins_compl_build_pum(void)
} while (compl != NULL && !is_first_match(compl));
if (compl_fuzzy_match && compl_leader != NULL && lead_len > 0)
+ {
+ for (i = 0; i < compl_match_arraysize; i++)
+ compl_match_array[i].pum_idx = i;
// sort by the largest score of fuzzy match
- qsort(compl_match_array, (size_t)compl_match_arraysize, sizeof(pumitem_T), ins_compl_fuzzy_sort);
+ qsort(compl_match_array, (size_t)compl_match_arraysize,
+ sizeof(pumitem_T), ins_compl_fuzzy_cmp);
+ }
if (!shown_match_ok) // no displayed match at all
cur = -1;