summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-29 18:58:01 +0100
committerBram Moolenaar <Bram@vim.org>2020-10-29 18:58:01 +0100
commitdcdd42a8ccb9bafd857735d694b074269f337333 (patch)
treee1271c66ae7fe5b284c44c668af37eaae1b9c346
parentcf4d454df0619ee41ef40e7e91fce3fb061d7d5b (diff)
patch 8.2.1921: fuzzy matching does not recognize path separatorsv8.2.1921
Problem: Fuzzy matching does not recognize path separators. Solution: Add a bonus for slash and backslash. (Yegappan Lakshmanan, closes #7225)
-rw-r--r--src/search.c16
-rw-r--r--src/testdir/test_matchfuzzy.vim2
-rw-r--r--src/version.c2
3 files changed, 13 insertions, 7 deletions
diff --git a/src/search.c b/src/search.c
index ebeb3f9b98..cc7b5a9792 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4258,8 +4258,10 @@ typedef struct
// bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that
// matching a whole word is preferred.
#define SEQUENTIAL_BONUS 40
-// bonus if match occurs after a separator
-#define SEPARATOR_BONUS 30
+// bonus if match occurs after a path separator
+#define PATH_SEPARATOR_BONUS 30
+// bonus if match occurs after a word separator
+#define WORD_SEPARATOR_BONUS 25
// bonus if match is uppercase and prev is lower
#define CAMEL_BONUS 30
// bonus if the first letter is matched
@@ -4334,7 +4336,6 @@ fuzzy_match_compute_score(
// Camel case
int neighbor = ' ';
int curr;
- int neighborSeparator;
if (has_mbyte)
{
@@ -4355,10 +4356,11 @@ fuzzy_match_compute_score(
if (vim_islower(neighbor) && vim_isupper(curr))
score += CAMEL_BONUS;
- // Separator
- neighborSeparator = neighbor == '_' || neighbor == ' ';
- if (neighborSeparator)
- score += SEPARATOR_BONUS;
+ // Bonus if the match follows a separator character
+ if (neighbor == '/' || neighbor == '\\')
+ score += PATH_SEPARATOR_BONUS;
+ else if (neighbor == ' ' || neighbor == '_')
+ score += WORD_SEPARATOR_BONUS;
}
else
{
diff --git a/src/testdir/test_matchfuzzy.vim b/src/testdir/test_matchfuzzy.vim
index 92de8b8369..d695456a88 100644
--- a/src/testdir/test_matchfuzzy.vim
+++ b/src/testdir/test_matchfuzzy.vim
@@ -43,6 +43,8 @@ func Test_matchfuzzy()
call assert_equal(['.vim/vimrc', '.vim/vimrc_colors', '.vim/v_i_m_r_c'], ['.vim/vimrc', '.vim/vimrc_colors', '.vim/v_i_m_r_c']->matchfuzzy('vimrc'))
" gap penalty
call assert_equal(['xxayybxxxx', 'xxayyybxxx', 'xxayyyybxx'], ['xxayyyybxx', 'xxayyybxxx', 'xxayybxxxx']->matchfuzzy('ab'))
+ " path separator vs word separator
+ call assert_equal(['color/setup.vim', 'color\\setup.vim', 'color setup.vim', 'color_setup.vim', 'colorsetup.vim'], matchfuzzy(['colorsetup.vim', 'color setup.vim', 'color/setup.vim', 'color_setup.vim', 'color\\setup.vim'], 'setup.vim'))
" match multiple words (separated by space)
call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo'))
diff --git a/src/version.c b/src/version.c
index 7031dc5ac9..1cdfb47516 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1921,
+/**/
1920,
/**/
1919,