From 46c7faa00b165a1ad1b7cef8245df30d3dc3ef56 Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 27 Dec 2024 14:23:06 +0800 Subject: 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 https://github.com/vim/vim/commit/5a04999a7402201cf1b47ff10bc474dd1cdc24f4 --- src/nvim/search.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/nvim/search.c b/src/nvim/search.c index faa14dfaf4..5a53122739 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -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; } -- cgit