Skip to content

Commit dcdd42a

Browse files
committed
patch 8.2.1921: fuzzy matching does not recognize path separators
Problem: Fuzzy matching does not recognize path separators. Solution: Add a bonus for slash and backslash. (Yegappan Lakshmanan, closes #7225)
1 parent cf4d454 commit dcdd42a

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/search.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,8 +4258,10 @@ typedef struct
42584258
// bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that
42594259
// matching a whole word is preferred.
42604260
#define SEQUENTIAL_BONUS 40
4261-
// bonus if match occurs after a separator
4262-
#define SEPARATOR_BONUS 30
4261+
// bonus if match occurs after a path separator
4262+
#define PATH_SEPARATOR_BONUS 30
4263+
// bonus if match occurs after a word separator
4264+
#define WORD_SEPARATOR_BONUS 25
42634265
// bonus if match is uppercase and prev is lower
42644266
#define CAMEL_BONUS 30
42654267
// bonus if the first letter is matched
@@ -4334,7 +4336,6 @@ fuzzy_match_compute_score(
43344336
// Camel case
43354337
int neighbor = ' ';
43364338
int curr;
4337-
int neighborSeparator;
43384339

43394340
if (has_mbyte)
43404341
{
@@ -4355,10 +4356,11 @@ fuzzy_match_compute_score(
43554356
if (vim_islower(neighbor) && vim_isupper(curr))
43564357
score += CAMEL_BONUS;
43574358

4358-
// Separator
4359-
neighborSeparator = neighbor == '_' || neighbor == ' ';
4360-
if (neighborSeparator)
4361-
score += SEPARATOR_BONUS;
4359+
// Bonus if the match follows a separator character
4360+
if (neighbor == '/' || neighbor == '\\')
4361+
score += PATH_SEPARATOR_BONUS;
4362+
else if (neighbor == ' ' || neighbor == '_')
4363+
score += WORD_SEPARATOR_BONUS;
43624364
}
43634365
else
43644366
{

src/testdir/test_matchfuzzy.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func Test_matchfuzzy()
4343
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'))
4444
" gap penalty
4545
call assert_equal(['xxayybxxxx', 'xxayyybxxx', 'xxayyyybxx'], ['xxayyyybxx', 'xxayyybxxx', 'xxayybxxxx']->matchfuzzy('ab'))
46+
" path separator vs word separator
47+
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'))
4648

4749
" match multiple words (separated by space)
4850
call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo'))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1921,
753755
/**/
754756
1920,
755757
/**/

0 commit comments

Comments
 (0)