Mercurial > vim
diff src/search.c @ 23475:79fd5217b125 v8.2.2280
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Commit: https://github.com/vim/vim/commit/9d19e4f4ba55f8bef18d4991abdf740ff6472dba
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 2 18:31:32 2021 +0100
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Problem: Fuzzy matching doesn't give access to the scores.
Solution: Return the scores with a third list. (Yegappan Lakshmanan,
closes #7596)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 Jan 2021 18:45:03 +0100 |
parents | a84e7abb0c92 |
children | bb29b09902d5 |
line wrap: on
line diff
--- a/src/search.c +++ b/src/search.c @@ -4723,10 +4723,10 @@ fuzzy_match_in_list( // For matchfuzzy(), return a list of matched strings. // ['str1', 'str2', 'str3'] - // For matchfuzzypos(), return a list with two items. + // For matchfuzzypos(), return a list with three items. // The first item is a list of matched strings. The second item // is a list of lists where each list item is a list of matched - // character positions. + // character positions. The third item is a list of matching scores. // [['str1', 'str2', 'str3'], [[1, 3], [1, 3], [1, 3]]] if (retmatchpos) { @@ -4749,7 +4749,7 @@ fuzzy_match_in_list( // next copy the list of matching positions if (retmatchpos) { - li = list_find(fmatchlist, -1); + li = list_find(fmatchlist, -2); if (li == NULL || li->li_tv.vval.v_list == NULL) goto done; l = li->li_tv.vval.v_list; @@ -4762,6 +4762,19 @@ fuzzy_match_in_list( list_append_list(l, ptrs[i].lmatchpos) == FAIL) goto done; } + + // copy the matching scores + li = list_find(fmatchlist, -1); + if (li == NULL || li->li_tv.vval.v_list == NULL) + goto done; + l = li->li_tv.vval.v_list; + for (i = 0; i < len; i++) + { + if (ptrs[i].score == SCORE_NONE) + break; + if (list_append_number(l, ptrs[i].score) == FAIL) + goto done; + } } } @@ -4842,9 +4855,15 @@ do_fuzzymatch(typval_T *argvars, typval_ { list_T *l; - // For matchfuzzypos(), a list with two items are returned. First item - // is a list of matching strings and the second item is a list of - // lists with matching positions within each string. + // For matchfuzzypos(), a list with three items are returned. First + // item is a list of matching strings, the second item is a list of + // lists with matching positions within each string and the third item + // is the list of scores of the matches. + l = list_alloc(); + if (l == NULL) + goto done; + if (list_append_list(rettv->vval.v_list, l) == FAIL) + goto done; l = list_alloc(); if (l == NULL) goto done;