Skip to content

Commit

Permalink
Handle a potential null value
Browse files Browse the repository at this point in the history
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: #198
  • Loading branch information
walles committed Mar 20, 2024
1 parent e92b01d commit 056c766
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion m/scrollPosition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 056c766

Please sign in to comment.