diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2022-11-18 16:18:11 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2022-11-18 20:16:43 +0900 |
commit | 1bebd6f4f5fac7c98ad01696fd819c3c82e41ec6 (patch) | |
tree | 93e6f1e4c1528fc2cd8f1035b82555fd02978c88 /src/result.go | |
parent | 3da63f394d016b6ad1861a022ea60b597d6ac030 (diff) |
Fix panic on inverse match query with `--tiebreak=chunk`
Fix #3055
Diffstat (limited to 'src/result.go')
-rw-r--r-- | src/result.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/result.go b/src/result.go index c4acb5fa..1212cabe 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: |