diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-02 18:31:32 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-02 18:31:32 +0100 |
commit | 9d19e4f4ba55f8bef18d4991abdf740ff6472dba (patch) | |
tree | c5bd4e0ba05fb3089d3acedee4e32729b2f5c3a4 /src/search.c | |
parent | 508b5618ec0bc6d1edff71e04d99280a2a51df9d (diff) | |
download | vim-git-9d19e4f4ba55f8bef18d4991abdf740ff6472dba.tar.gz |
patch 8.2.2280: fuzzy matching doesn't give access to the scoresv8.2.2280
Problem: Fuzzy matching doesn't give access to the scores.
Solution: Return the scores with a third list. (Yegappan Lakshmanan,
closes #7596)
Diffstat (limited to 'src/search.c')
-rw-r--r-- | src/search.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/search.c b/src/search.c index af2b80259..6305b58b1 100644 --- 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_T *rettv, int retmatchpos) { 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; |