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
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
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:
// 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

View File

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