Skip to content
Myr

Fix --tiebreak=begin with algo v2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Junegunn Choi · committed by Junegunn Choi · parent c95bb10 · Browse files · 1 file+3 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−1 removed

  • other:+3 added−1 removed

1 file+3 added−1 removed

modified:src/result.go+3 added-1 removed
35 unmodified lines
3637 result := Result{item: item, rank: rank{index: item.index}}38 numChars := item.text.Length()39 minBegin := math.MaxUint1640 minEnd := math.MaxUint1641 maxEnd := 042 validOffsetFound := false43 for _, offset := range offsets {44 b, e := int(offset[0]), int(offset[1])45 if b < e {46 minBegin = util.Min(b, minBegin)47 minEnd = util.Min(e, minEnd)48 maxEnd = util.Max(e, maxEnd)49 validOffsetFound = true50 }51 }
17 unmodified lines
69 break70 }71 }72 if criterion == byBegin {71 val = util.AsUint16(minBegin - whitePrefixLen)73 val = util.AsUint16(minEnd - whitePrefixLen)74 } else {75 val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen)76 }77 }
168 unmodified lines