comparison src/search.c @ 22746:875bd7c04533 v8.2.1921

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 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 29 Oct 2020 19:00:04 +0100
parents e82579016863
children b545334ae654
comparison
equal deleted inserted replaced
22745:34e09ca2ddb7 22746:875bd7c04533
4256 } fuzzyItem_T; 4256 } fuzzyItem_T;
4257 4257
4258 // bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that 4258 // bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that
4259 // matching a whole word is preferred. 4259 // matching a whole word is preferred.
4260 #define SEQUENTIAL_BONUS 40 4260 #define SEQUENTIAL_BONUS 40
4261 // bonus if match occurs after a separator 4261 // bonus if match occurs after a path separator
4262 #define SEPARATOR_BONUS 30 4262 #define PATH_SEPARATOR_BONUS 30
4263 // bonus if match occurs after a word separator
4264 #define WORD_SEPARATOR_BONUS 25
4263 // bonus if match is uppercase and prev is lower 4265 // bonus if match is uppercase and prev is lower
4264 #define CAMEL_BONUS 30 4266 #define CAMEL_BONUS 30
4265 // bonus if the first letter is matched 4267 // bonus if the first letter is matched
4266 #define FIRST_LETTER_BONUS 15 4268 #define FIRST_LETTER_BONUS 15
4267 // penalty applied for every letter in str before the first match 4269 // penalty applied for every letter in str before the first match
4332 if (currIdx > 0) 4334 if (currIdx > 0)
4333 { 4335 {
4334 // Camel case 4336 // Camel case
4335 int neighbor = ' '; 4337 int neighbor = ' ';
4336 int curr; 4338 int curr;
4337 int neighborSeparator;
4338 4339
4339 if (has_mbyte) 4340 if (has_mbyte)
4340 { 4341 {
4341 while (sidx < currIdx) 4342 while (sidx < currIdx)
4342 { 4343 {
4353 } 4354 }
4354 4355
4355 if (vim_islower(neighbor) && vim_isupper(curr)) 4356 if (vim_islower(neighbor) && vim_isupper(curr))
4356 score += CAMEL_BONUS; 4357 score += CAMEL_BONUS;
4357 4358
4358 // Separator 4359 // Bonus if the match follows a separator character
4359 neighborSeparator = neighbor == '_' || neighbor == ' '; 4360 if (neighbor == '/' || neighbor == '\\')
4360 if (neighborSeparator) 4361 score += PATH_SEPARATOR_BONUS;
4361 score += SEPARATOR_BONUS; 4362 else if (neighbor == ' ' || neighbor == '_')
4363 score += WORD_SEPARATOR_BONUS;
4362 } 4364 }
4363 else 4365 else
4364 { 4366 {
4365 // First letter 4367 // First letter
4366 score += FIRST_LETTER_BONUS; 4368 score += FIRST_LETTER_BONUS;