vim-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 vim/vim#7225)
dcdd42a8cc
This commit is contained in:
Sean Dewar 2022-01-01 22:35:43 +00:00
parent 30deb14f39
commit 712c7e5d5f
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
2 changed files with 11 additions and 6 deletions

View File

@ -4823,8 +4823,10 @@ typedef struct {
/// bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that /// bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that
/// matching a whole word is preferred. /// matching a whole word is preferred.
#define SEQUENTIAL_BONUS 40 #define SEQUENTIAL_BONUS 40
/// bonus if match occurs after a separator /// bonus if match occurs after a path separator
#define SEPARATOR_BONUS 30 #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 /// bonus if match is uppercase and prev is lower
#define CAMEL_BONUS 30 #define CAMEL_BONUS 30
/// bonus if the first letter is matched /// bonus if the first letter is matched
@ -4895,10 +4897,11 @@ static int fuzzy_match_compute_score(const char_u *const str, const int strSz,
score += CAMEL_BONUS; score += CAMEL_BONUS;
} }
// Separator // Bonus if the match follows a separator character
const bool neighborSeparator = neighbor == '_' || neighbor == ' '; if (neighbor == '/' || neighbor == '\\') {
if (neighborSeparator) { score += PATH_SEPARATOR_BONUS;
score += SEPARATOR_BONUS; } else if (neighbor == ' ' || neighbor == '_') {
score += WORD_SEPARATOR_BONUS;
} }
} else { } else {
// First letter // First letter

View File

@ -45,6 +45,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')) 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 " gap penalty
call assert_equal(['xxayybxxxx', 'xxayyybxxx', 'xxayyyybxx'], ['xxayyyybxx', 'xxayyybxxx', 'xxayybxxxx']->matchfuzzy('ab')) 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) " match multiple words (separated by space)
call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo')) call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo'))