diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2022-02-27 04:36:04 +0000 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-01-17 14:01:26 +0800 |
commit | 0c689fec8e7e1c9eb0bcdf84949160cd7caf3fb6 (patch) | |
tree | 222e1a6ebec01aeb522a87861047bf8cdf9ede2e /src/nvim/cmdexpand.c | |
parent | 6734dd250355f8621a710d59c2089b38a65dbf18 (diff) | |
download | rneovim-0c689fec8e7e1c9eb0bcdf84949160cd7caf3fb6.tar.gz rneovim-0c689fec8e7e1c9eb0bcdf84949160cd7caf3fb6.tar.bz2 rneovim-0c689fec8e7e1c9eb0bcdf84949160cd7caf3fb6.zip |
vim-patch:8.2.4465: fuzzy completion does not order matches properly
Problem: Fuzzy completion does not order matches properly.
Solution: Do not use regular expression match. (Yegappan Lakshmanan,
closes vim/vim#9843)
https://github.com/vim/vim/commit/5ec633b9b0400519db60253cb5846e50394218b4
Nvim's ExpandGeneric() was refactored to eliminate looping for "round",
so the patch has been adapted.
fuzzy_match_str() change was already applied earlier.
In Test_wildoptions_fuzzy(), test for NvimParenthesis over MatchParen
for :syntax list, as the fuzzy matching algorithm prefers the former
(even in Vim).
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r-- | src/nvim/cmdexpand.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index f18869bb1c..566a17b82b 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2765,8 +2765,14 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, char ***matches, i if (*str == NUL) { // skip empty strings continue; } - if (vim_regexec(regmatch, str, (colnr_T)0) - || (fuzzy && fuzzy_match_str(str, fuzzystr) != 0)) { + + bool match; + if (!fuzzy) { + match = vim_regexec(regmatch, str, (colnr_T)0); + } else { + match = fuzzy_match_str(str, fuzzystr) != 0; + } + if (match) { count++; } } @@ -2792,28 +2798,37 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, char ***matches, i if (*str == NUL) { // Skip empty strings. continue; } - int score; - if (vim_regexec(regmatch, str, (colnr_T)0) - || (fuzzy && ((score = fuzzy_match_str(str, fuzzystr)) != 0))) { - if (escaped) { - str = vim_strsave_escaped(str, " \t\\."); - } else { - str = xstrdup(str); - } - if (fuzzy) { - fuzmatch[count].idx = (int)count; - fuzmatch[count].str = str; - fuzmatch[count].score = score; - } else { - (*matches)[count] = str; - } - count++; - if (func == get_menu_names) { - // Test for separator added by get_menu_names(). - str += strlen(str) - 1; - if (*str == '\001') { - *str = '.'; - } + + bool match; + int score = 0; + if (!fuzzy) { + match = vim_regexec(regmatch, str, (colnr_T)0); + } else { + score = fuzzy_match_str(str, fuzzystr); + match = (score != 0); + } + if (!match) { + continue; + } + + if (escaped) { + str = vim_strsave_escaped(str, " \t\\."); + } else { + str = xstrdup(str); + } + if (fuzzy) { + fuzmatch[count].idx = (int)count; + fuzmatch[count].str = str; + fuzmatch[count].score = score; + } else { + (*matches)[count] = str; + } + count++; + if (func == get_menu_names) { + // Test for separator added by get_menu_names(). + str += strlen(str) - 1; + if (*str == '\001') { + *str = '.'; } } } |