mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 11:29:01 +00: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:
parent
47b11cb8b4
commit
0541c0dbcf
@ -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
|
||||
}
|
||||
}
|
||||
if criterion == byBegin {
|
||||
val = util.AsUint16(minBegin - whitePrefixLen)
|
||||
} else {
|
||||
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen)
|
||||
}
|
||||
case byEnd:
|
||||
if validOffsetFound {
|
||||
val = util.AsUint16(1 + numChars - maxEnd)
|
||||
}
|
||||
}
|
||||
result.rank.points[idx] = val
|
||||
|
@ -604,8 +604,8 @@ class TestGoFZF < TestBase
|
||||
], `#{FZF} -fo --tiebreak=end < #{tempname}`.split($/)
|
||||
|
||||
assert_equal [
|
||||
' xxxxoxxx',
|
||||
'xxxxxoxxx',
|
||||
' xxxxoxxx',
|
||||
'xxxxoxxxx',
|
||||
'xxxoxxxxxx',
|
||||
'xxoxxxxxxx',
|
||||
|
Loading…
Reference in New Issue
Block a user