summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-02-02 13:46:46 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-02-02 13:46:46 +0900
commitfcf63c74f1de52e4b0038a50154ee1732ef84af5 (patch)
tree40c43059b15627bde4bce4d9c02f96d8d0e6050c /src
parentc95bb109c83f8a1b7b4a7c316ab7f0c1ef845cd9 (diff)
Fix --tiebreak=begin with algo v2
Due to performance consideration, FuzzyMatchV2 does not return the exact positions of the matching characters by default. However, the ommission caused `--tiebreak=begin` to produce inaccurate result in some cases. (echo baz foo bar; echo foo bar baz) | fzf --tiebreak=begin -fbar | head -1 # Expected: foo bar baz # Actual: baz foo bar This commit fixes the problem by using the end offset which is guaranteed to be correct.
Diffstat (limited to 'src')
-rw-r--r--src/result.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/result.go b/src/result.go
index 3d79176f..e071a9ee 100644
--- a/src/result.go
+++ b/src/result.go
@@ -37,12 +37,14 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result {
result := Result{item: item, rank: rank{index: item.index}}
numChars := item.text.Length()
minBegin := math.MaxUint16
+ minEnd := math.MaxUint16
maxEnd := 0
validOffsetFound := false
for _, offset := range offsets {
b, e := int(offset[0]), int(offset[1])
if b < e {
minBegin = util.Min(b, minBegin)
+ minEnd = util.Min(e, minEnd)
maxEnd = util.Max(e, maxEnd)
validOffsetFound = true
}
@@ -68,7 +70,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result {
}
}
if criterion == byBegin {
- val = util.AsUint16(minBegin - whitePrefixLen)
+ val = util.AsUint16(minEnd - whitePrefixLen)
} else {
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen)
}