diff 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
line wrap: on
line diff
--- a/src/search.c
+++ b/src/search.c
@@ -4258,8 +4258,10 @@ typedef struct
 // bonus for adjacent matches; this is higher than SEPARATOR_BONUS so that
 // matching a whole word is preferred.
 #define SEQUENTIAL_BONUS 40
-// bonus if match occurs after a separator
-#define SEPARATOR_BONUS 30
+// bonus if match occurs after a path separator
+#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
 #define CAMEL_BONUS 30
 // bonus if the first letter is matched
@@ -4334,7 +4336,6 @@ fuzzy_match_compute_score(
 	    // Camel case
 	    int	neighbor = ' ';
 	    int	curr;
-	    int	neighborSeparator;
 
 	    if (has_mbyte)
 	    {
@@ -4355,10 +4356,11 @@ fuzzy_match_compute_score(
 	    if (vim_islower(neighbor) && vim_isupper(curr))
 		score += CAMEL_BONUS;
 
-	    // Separator
-	    neighborSeparator = neighbor == '_' || neighbor == ' ';
-	    if (neighborSeparator)
-		score += SEPARATOR_BONUS;
+	    // Bonus if the match follows a separator character
+	    if (neighbor == '/' || neighbor == '\\')
+		score += PATH_SEPARATOR_BONUS;
+	    else if (neighbor == ' ' || neighbor == '_')
+		score += WORD_SEPARATOR_BONUS;
 	}
 	else
 	{