Fix unexpected result of --tiebreak=end

See https://github.com/junegunn/fzf/issues/3255#issuecomment-1869580320
This commit is contained in:
Junegunn Choi 2023-12-26 23:40:20 +09:00
parent 97ccef1a04
commit 519de7c833
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 7 additions and 1 deletions

View File

@ -80,7 +80,7 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
if criterion == byBegin {
val = util.AsUint16(minEnd - whitePrefixLen)
} else {
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength()))
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength()+1))
}
}
}

View File

@ -741,6 +741,12 @@ class TestGoFZF < TestBase
'xxoxxxxxxx',
'xoxxxxxxxx'
], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)
writelines(tempname, ['/bar/baz', '/foo/bar/baz'])
assert_equal [
'/foo/bar/baz',
'/bar/baz',
], `#{FZF} -fbaz --tiebreak=end < #{tempname}`.lines(chomp: true)
end
def test_tiebreak_length_with_nth