diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d460a..de3b9af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/result.go b/src/result.go index c4acb5f..1212cab 100644 --- a/src/result.go +++ b/src/result.go @@ -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: diff --git a/test/test_go.rb b/test/test_go.rb index 41767fc..b7ae151 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -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