summaryrefslogtreecommitdiff
path: root/src/algo
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-08-16 19:20:30 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-08-29 17:08:23 +0900
commit4ae3069c6fc3e3f2427557bf4813867a621c79ad (patch)
tree3b39258f9b8d0265c36e8456bf36ca07a2f23a55 /src/algo
parentc0f27751d378b0be0aeb0572dbeaac24153a3137 (diff)
downloadfzf-4ae3069c6fc3e3f2427557bf4813867a621c79ad.tar.gz
Underscore boundaries should be ranked lower
Diffstat (limited to 'src/algo')
-rw-r--r--src/algo/algo.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/algo/algo.go b/src/algo/algo.go
index a02a0a81..f0569185 100644
--- a/src/algo/algo.go
+++ b/src/algo/algo.go
@@ -847,6 +847,9 @@ func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryC
}
if boundaryCheck {
ok = bonus >= bonusBoundary
+ if ok && pidx_ == 0 {
+ ok = index_ == 0 || charClassOf(text.Get(index_-1)) <= charDelimiter
+ }
if ok && pidx_ == len(pattern)-1 {
ok = index_ == lenRunes-1 || charClassOf(text.Get(index_+1)) <= charDelimiter
}
@@ -878,7 +881,23 @@ func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryC
sidx = lenRunes - (bestPos + 1)
eidx = lenRunes - (bestPos - lenPattern + 1)
}
- score, _ := calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false)
+ var score int
+ if boundaryCheck {
+ // Underscore boundaries should be ranked lower than the other types of boundaries
+ score = int(bonus)
+ deduct := int(bonus-bonusBoundary) + 1
+ if sidx > 0 && text.Get(sidx-1) == '_' {
+ score -= deduct + 1
+ deduct = 1
+ }
+ if eidx < lenRunes && text.Get(eidx) == '_' {
+ score -= deduct
+ }
+ // Add base score so that this can compete with other match types e.g. 'foo' | bar
+ score += scoreMatch*lenPattern + int(bonusBoundaryWhite)*(lenPattern+1)
+ } else {
+ score, _ = calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false)
+ }
return Result{sidx, eidx, score}, nil
}
return Result{-1, -1, 0}, nil