summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-19 08:26:22 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commit9a2dc3fe150a03ccb4f086b05d8a8249c9e6c37f (patch)
tree7dd6da3dbf1907a04b1b865973f9dfdfd0ccc10e /pkg/gui
parentf0c3d3fc4d43f5b7487540d5c0356f62b3b2997d (diff)
stop crash due to context stack not being initialized
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/commits_panel.go2
-rw-r--r--pkg/gui/context.go19
-rw-r--r--pkg/gui/gui.go10
-rw-r--r--pkg/gui/layout.go2
-rw-r--r--pkg/gui/line_by_line_panel.go2
5 files changed, 23 insertions, 12 deletions
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 7f2df104b..6e5e2d201 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -96,7 +96,7 @@ func (gui *Gui) refreshCommits() error {
go func() {
_ = gui.refreshCommitsWithLimit()
- if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey()) {
+ if gui.g.CurrentView() == gui.getCommitFilesView() || (gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey()) {
_ = gui.refreshCommitFilesView()
}
wg.Done()
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 522932664..3c5dedde5 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -208,12 +208,17 @@ func (gui *Gui) renderContextStack() string {
return result
}
-func (gui *Gui) currentContext() Context {
- return gui.State.ContextStack[len(gui.State.ContextStack)-1]
+func (gui *Gui) currentContextKey() string {
+ // on startup the stack can be empty so we'll return an empty string in that case
+ if len(gui.State.ContextStack) == 0 {
+ return ""
+ }
+
+ return gui.State.ContextStack[len(gui.State.ContextStack)-1].GetKey()
}
-func (gui *Gui) createContextTree() {
- gui.Contexts = ContextTree{
+func (gui *Gui) contextTree() ContextTree {
+ return ContextTree{
Status: SimpleContextNode{
Context: BasicContext{
OnFocus: gui.handleStatusSelect,
@@ -329,8 +334,10 @@ func (gui *Gui) createContextTree() {
},
},
}
+}
- gui.State.ViewContextMap = map[string]Context{
+func (gui *Gui) initialViewContextMap() map[string]Context {
+ return map[string]Context{
"status": gui.Contexts.Status.Context,
"files": gui.Contexts.Files.Context,
"branches": gui.Contexts.Branches.Context,
@@ -344,7 +351,9 @@ func (gui *Gui) createContextTree() {
"main": gui.Contexts.Normal.Context,
"secondary": gui.Contexts.Normal.Context,
}
+}
+func (gui *Gui) setInitialViewContexts() {
// arguably we should only have our ViewContextMap and we should do away with
// contexts on views, or vice versa
for viewName, context := range gui.State.ViewContextMap {
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 1c0178fe8..cc083b4de 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -282,10 +282,11 @@ func (gui *Gui) resetState() {
EditHistory: stack.New(),
},
},
- SideView: nil,
- Ptmx: nil,
- FilterPath: prevFilterPath,
- Diff: prevDiff,
+ SideView: nil,
+ Ptmx: nil,
+ FilterPath: prevFilterPath,
+ Diff: prevDiff,
+ ViewContextMap: gui.initialViewContextMap(),
}
}
@@ -306,6 +307,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
gui.resetState()
gui.State.FilterPath = filterPath
+ gui.Contexts = gui.contextTree()
gui.watchFilesForChanges()
diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go
index 094c7271c..bc59bb5e2 100644
--- a/pkg/gui/layout.go
+++ b/pkg/gui/layout.go
@@ -337,7 +337,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
func (gui *Gui) onInitialViewsCreation() error {
- gui.createContextTree()
+ gui.setInitialViewContexts()
if err := gui.switchContext(gui.Contexts.Files.Context); err != nil {
return err
diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go
index 6bec51308..4ae8e741a 100644
--- a/pkg/gui/line_by_line_panel.go
+++ b/pkg/gui/line_by_line_panel.go
@@ -234,7 +234,7 @@ func (gui *Gui) refreshMainView() 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.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() {
+ if gui.currentContextKey() == gui.Contexts.PatchBuilding.Context.GetKey() {
filename := gui.getSelectedCommitFileName()
includedLineIndices = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename)
}