From 056c766bd3cc0948c0db8d4f1985718d2775e2e1 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Wed, 20 Mar 2024 06:55:29 +0100 Subject: [PATCH] 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 --- m/scrollPosition.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/m/scrollPosition.go b/m/scrollPosition.go index fe6b3a9..2438909 100644 --- a/m/scrollPosition.go +++ b/m/scrollPosition.go @@ -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) {