1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 21:50:43 +03:00

Handle a potential null value

I don't understand how this happens, but:
* It's uncommon
* It's been reported once during startup
* I'm assuming this is a race condition during startup
* Let's just treat the scroll position as zero if unset

Then let's cross our fingers and hope we don't crash anywhere else in
this situation.

Fixes: https://github.com/walles/moar/issues/198
This commit is contained in:
Johan Walles 2024-03-20 06:55:29 +01:00
parent e92b01da07
commit 056c766bd3

View File

@ -386,7 +386,12 @@ func numberPrefixLength(pager *Pager, scrollPosition scrollPositionInternal) int
// recursion.
//
// Let's improve on demand.
maxVisibleLineNumber := scrollPosition.lineNumber.NonWrappingAdd(
var lineNumber linenumbers.LineNumber
// Ref: https://github.com/walles/moar/issues/198
if scrollPosition.lineNumber != nil {
lineNumber = *scrollPosition.lineNumber
}
maxVisibleLineNumber := lineNumber.NonWrappingAdd(
scrollPosition.deltaScreenLines +
pager.visibleHeight() - 1)
if maxVisibleLineNumber.IsAfter(maxPossibleLineNumber) {