From 4198bbae6cc3747ee45d47648acab2b91f121272 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 23 Aug 2020 10:17:17 +1000 Subject: [PATCH] ensure there is always a current context --- pkg/gui/commits_panel.go | 2 +- pkg/gui/context.go | 13 +------------ pkg/gui/diffing.go | 4 ++-- pkg/gui/line_by_line_panel.go | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index c98c3f504..007f3f447 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -85,7 +85,7 @@ func (gui *Gui) refreshCommits() error { go func() { _ = gui.refreshCommitsWithLimit() - if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey()) { + if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey()) { _ = gui.refreshCommitFilesView() } wg.Done() diff --git a/pkg/gui/context.go b/pkg/gui/context.go index fe444321c..a1f0ae251 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -493,20 +493,9 @@ func (gui *Gui) renderContextStack() string { return result } -func (gui *Gui) currentContextKey() string { - currentContext := gui.currentContext() - - if currentContext == nil { - return "" - } - - return currentContext.GetKey() -} - func (gui *Gui) currentContext() Context { - // on startup the stack can be empty so we'll return an empty string in that case if len(gui.State.ContextStack) == 0 { - return nil + return gui.defaultSideContext() } return gui.State.ContextStack[len(gui.State.ContextStack)-1] diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 1da230a0d..c3cc40fa0 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -31,7 +31,7 @@ func (gui *Gui) renderDiff() error { // which becomes an option when you bring up the diff menu, but when you're just // flicking through branches it will be using the local branch name. func (gui *Gui) currentDiffTerminals() []string { - switch gui.currentContextKey() { + switch gui.currentContext().GetKey() { case "": return nil case FILES_CONTEXT_KEY: @@ -71,7 +71,7 @@ func (gui *Gui) currentDiffTerminal() string { } func (gui *Gui) currentlySelectedFilename() string { - switch gui.currentContextKey() { + switch gui.currentContext().GetKey() { case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY: return gui.getSideContextSelectedItemId() default: diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index a70b2e4ff..e06a685a6 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -234,7 +234,7 @@ func (gui *Gui) refreshMainViewForLineByLine() error { var includedLineIndices []int // I'd prefer not to have knowledge of contexts using this file but I'm not sure // how to get around this - if gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey() { + if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() { filename := gui.getSelectedCommitFileName() var err error includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename)