Fix panic on inverse match query with --tiebreak=chunk

Fix #3055
This commit is contained in:
Junegunn Choi 2022-11-18 16:18:11 +09:00
parent 3da63f394d
commit 1bebd6f4f5
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,10 @@
CHANGELOG
=========
0.35.1
------
- Fixed a bug where fzf with `--tiebreak=chunk` crashes on inverse match query
0.35.0
------
- Added `start` event that is triggered only once when fzf finder starts.

View File

@ -50,20 +50,21 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
// Higher is better
val = math.MaxUint16 - util.AsUint16(score)
case byChunk:
b := minBegin
e := maxEnd
l := item.text.Length()
for ; b >= 1; b-- {
if unicode.IsSpace(item.text.Get(b - 1)) {
break
if validOffsetFound {
b := minBegin
e := maxEnd
for ; b >= 1; b-- {
if unicode.IsSpace(item.text.Get(b - 1)) {
break
}
}
}
for ; e < l; e++ {
if unicode.IsSpace(item.text.Get(e)) {
break
for ; e < numChars; e++ {
if unicode.IsSpace(item.text.Get(e)) {
break
}
}
val = util.AsUint16(e - b)
}
val = util.AsUint16(e - b)
case byLength:
val = item.TrimLength()
case byBegin, byEnd:

View File

@ -779,6 +779,10 @@ class TestGoFZF < TestBase
'2 foobar baz',
'3 foo barbaz'
], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)
assert_equal [
'3 foo barbaz'
], `#{FZF} -f'!foobar' --tiebreak=chunk < #{tempname}`.lines(chomp: true)
end
def test_invalid_cache