From e36899d5c591c5045d1a5d676b92d61090b16e33 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 3 Mar 2019 23:08:07 +1100 Subject: [PATCH] prevent crashes when scrolling up --- pkg/gui/gui.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index a5db4c394..89b99a919 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -1,6 +1,7 @@ package gui import ( + "math" "sync" // "io" @@ -181,10 +182,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma func (gui *Gui) scrollUpMain(g *gocui.Gui, v *gocui.View) error { mainView, _ := g.View("main") ox, oy := mainView.Origin() - if oy >= 1 { - return mainView.SetOrigin(ox, oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight")) - } - return nil + newOy := int(math.Max(0, float64(oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight")))) + return mainView.SetOrigin(ox, newOy) } func (gui *Gui) scrollDownMain(g *gocui.Gui, v *gocui.View) error {