From 2746b1bd38fa2668490a8db2369dec5146fbaec6 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 6 May 2019 22:29:35 +1000 Subject: Prevent crash when opening in small window We were crashing when opening lazygit in a small window because the limit view was the only view that got created, and there were two functions that referenced either the 'current' view or the files view, neither of which existed. Now those functions just return nil if the view does not exist --- pkg/gui/context.go | 6 +++++- pkg/gui/files_panel.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'pkg/gui') diff --git a/pkg/gui/context.go b/pkg/gui/context.go index b741132ea..2cdc5c8c6 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -21,7 +21,11 @@ func (gui *Gui) contextTitleMap() map[string]map[string]string { } func (gui *Gui) setMainTitle() error { - currentViewName := gui.g.CurrentView().Name() + currentView := gui.g.CurrentView() + if currentView == nil { + return nil + } + currentViewName := currentView.Name() var newTitle string if context, ok := gui.State.Contexts[currentViewName]; ok { newTitle = gui.contextTitleMap()[currentViewName][context] diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index caab1bede..3d2001ac1 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -86,6 +86,10 @@ func (gui *Gui) refreshFiles() error { selectedFile, _ := gui.getSelectedFile(gui.g) filesView := gui.getFilesView() + if filesView == nil { + // if the filesView hasn't been instantiated yet we just return + return nil + } if err := gui.refreshStateFiles(); err != nil { return err } -- cgit v1.2.3