1
1
mirror of https://github.com/walles/moar.git synced 2024-11-30 12:42:26 +03:00

Don't crash searching in empty buffer

This commit is contained in:
Johan Walles 2024-05-18 07:59:44 +02:00
parent 64ae443e1f
commit 60d3577b59

View File

@ -15,10 +15,16 @@ func (p *Pager) scrollToSearchHits() {
return return
} }
firstHitPosition := p.findFirstHit(*p.scrollPosition.lineNumber(p), nil, false) lineNumber := p.scrollPosition.lineNumber(p)
if lineNumber == nil {
// No lines to search
return
}
firstHitPosition := p.findFirstHit(*lineNumber, nil, false)
if firstHitPosition == nil { if firstHitPosition == nil {
// Try again from the top // Try again from the top
firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, p.scrollPosition.lineNumber(p), false) firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, lineNumber, false)
} }
if firstHitPosition == nil { if firstHitPosition == nil {
// No match, give up // No match, give up