From 0541c0dbcf96ff40bd80cb8359191dc0fa01d83d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 18 Oct 2016 01:11:04 +0900 Subject: Use relative position instead of absolute distance for --tiebreak=end Fix unintuitive result where `*fzf*/install` is ranked higher than `fzf/src/fzf/*fzf*-linux_386` on --tiebreak=end. --- src/result.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/result.go') diff --git a/src/result.go b/src/result.go index bc1deb47..347cf599 100644 --- a/src/result.go +++ b/src/result.go @@ -57,7 +57,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { case byLength: // If offsets is empty, trimLen will be 0, but we don't care val = util.AsUint16(trimLen) - case byBegin: + case byBegin, byEnd: if validOffsetFound { whitePrefixLen := 0 for idx := 0; idx < numChars; idx++ { @@ -67,11 +67,11 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { break } } - val = util.AsUint16(minBegin - whitePrefixLen) - } - case byEnd: - if validOffsetFound { - val = util.AsUint16(1 + numChars - maxEnd) + if criterion == byBegin { + val = util.AsUint16(minBegin - whitePrefixLen) + } else { + val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen) + } } } result.rank.points[idx] = val -- cgit v1.2.3