m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 23:33:39 -05:00

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.
This commit is contained in:
Junegunn Choi
2016-10-18 01:11:04 +09:00
parent 47b11cb8b4
commit 0541c0dbcf
2 changed files with 7 additions and 7 deletions

View File

@@ -57,7 +57,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result {
case byLength: case byLength:
// If offsets is empty, trimLen will be 0, but we don't care // If offsets is empty, trimLen will be 0, but we don't care
val = util.AsUint16(trimLen) val = util.AsUint16(trimLen)
case byBegin: case byBegin, byEnd:
if validOffsetFound { if validOffsetFound {
whitePrefixLen := 0 whitePrefixLen := 0
for idx := 0; idx < numChars; idx++ { for idx := 0; idx < numChars; idx++ {
@@ -67,11 +67,11 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result {
break break
} }
} }
val = util.AsUint16(minBegin - whitePrefixLen) if criterion == byBegin {
} val = util.AsUint16(minBegin - whitePrefixLen)
case byEnd: } else {
if validOffsetFound { val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen)
val = util.AsUint16(1 + numChars - maxEnd) }
} }
} }
result.rank.points[idx] = val result.rank.points[idx] = val

View File

@@ -604,8 +604,8 @@ class TestGoFZF < TestBase
], `#{FZF} -fo --tiebreak=end < #{tempname}`.split($/) ], `#{FZF} -fo --tiebreak=end < #{tempname}`.split($/)
assert_equal [ assert_equal [
' xxxxoxxx',
'xxxxxoxxx', 'xxxxxoxxx',
' xxxxoxxx',
'xxxxoxxxx', 'xxxxoxxxx',
'xxxoxxxxxx', 'xxxoxxxxxx',
'xxoxxxxxxx', 'xxoxxxxxxx',