Mirror of the Vim source from https://github.com/vim/vim
修訂 | 875bd7c04533350c2d64e9fa3ce87ae0cf8a7891 (tree) |
---|---|
時間 | 2020-10-30 03:00:04 |
作者 | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.1921: fuzzy matching does not recognize path separators
Commit: https://github.com/vim/vim/commit/dcdd42a8ccb9bafd857735d694b074269f337333
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 29 18:58:01 2020 +0100
@@ -4258,8 +4258,10 @@ | ||
4258 | 4258 | // bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that |
4259 | 4259 | // matching a whole word is preferred. |
4260 | 4260 | #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 | |
4263 | 4265 | // bonus if match is uppercase and prev is lower |
4264 | 4266 | #define CAMEL_BONUS 30 |
4265 | 4267 | // bonus if the first letter is matched |
@@ -4334,7 +4336,6 @@ | ||
4334 | 4336 | // Camel case |
4335 | 4337 | int neighbor = ' '; |
4336 | 4338 | int curr; |
4337 | - int neighborSeparator; | |
4338 | 4339 | |
4339 | 4340 | if (has_mbyte) |
4340 | 4341 | { |
@@ -4355,10 +4356,11 @@ | ||
4355 | 4356 | if (vim_islower(neighbor) && vim_isupper(curr)) |
4356 | 4357 | score += CAMEL_BONUS; |
4357 | 4358 | |
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; | |
4362 | 4364 | } |
4363 | 4365 | else |
4364 | 4366 | { |
@@ -43,6 +43,8 @@ | ||
43 | 43 | 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')) |
44 | 44 | " gap penalty |
45 | 45 | 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')) | |
46 | 48 | |
47 | 49 | " match multiple words (separated by space) |
48 | 50 | call assert_equal(['foo bar baz'], ['foo bar baz', 'foo', 'foo bar', 'baz bar']->matchfuzzy('baz foo')) |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 1921, | |
755 | +/**/ | |
754 | 756 | 1920, |
755 | 757 | /**/ |
756 | 758 | 1919, |