vim-patch:9.1.0963: fuzzy-matching does not prefer full match (#31741)

Problem:  fuzzy-matching does not prefer full match
          (Maxim Kim)
Solution: add additional score for a full match
          (glepnir)

fixes: vim/vim#15654
closes: vim/vim#16300

5a04999a74
This commit is contained in:
glepnir
2024-12-27 14:23:06 +08:00
committed by GitHub
parent 557f2d9700
commit 46c7faa00b
3 changed files with 14 additions and 2 deletions

View File

@@ -2995,6 +2995,7 @@ static int fuzzy_match_compute_score(const char *const str, const int strSz,
assert(numMatches > 0); // suppress clang "result of operation is garbage"
// Initialize score
int score = 100;
bool is_exact_match = true;
// Apply leading letter penalty
int penalty = LEADING_LETTER_PENALTY * (int)matches[0];
@@ -3048,6 +3049,14 @@ static int fuzzy_match_compute_score(const char *const str, const int strSz,
// First letter
score += FIRST_LETTER_BONUS;
}
// Check exact match condition
if (currIdx != (uint32_t)i) {
is_exact_match = false;
}
}
// Boost score for exact matches
if (is_exact_match && numMatches == strSz) {
score += 100;
}
return score;
}