summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-29 10:35:12 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-29 11:37:29 +1100
commitd90d9d7330ff5ba5161c70d6b8e11cb7b87c9b47 (patch)
treeb972890726ff846b5fdd5f7d659c0f31a7bf2aca
parenta8db672ffbeba92a32ad34f475760c78aa73303e (diff)
reset state on each Run() call
-rw-r--r--pkg/gui/filtering_menu_panel.go (renamed from pkg/gui/scoping_menu_panel.go)0
-rw-r--r--pkg/gui/gui.go2
-rw-r--r--pkg/gui/recent_repos_panel.go1
-rw-r--r--pkg/gui/reflog_panel.go17
4 files changed, 15 insertions, 5 deletions
diff --git a/pkg/gui/scoping_menu_panel.go b/pkg/gui/filtering_menu_panel.go
index 316ea95d0..316ea95d0 100644
--- a/pkg/gui/scoping_menu_panel.go
+++ b/pkg/gui/filtering_menu_panel.go
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index db866356f..9e2130628 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -283,6 +283,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
// Run setup the gui with keybindings and start the mainloop
func (gui *Gui) Run() error {
+ gui.resetState()
+
g, err := gocui.NewGui(gocui.Output256, OverlappingEdges)
if err != nil {
return err
diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go
index 62c11edfe..517650d5f 100644
--- a/pkg/gui/recent_repos_panel.go
+++ b/pkg/gui/recent_repos_panel.go
@@ -32,6 +32,7 @@ func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error {
return err
}
gui.GitCommand = newGitCommand
+ gui.State.FilterPath = ""
return gui.Errors.ErrSwitchRepo
},
}
diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go
index 55738c445..f8fa5e618 100644
--- a/pkg/gui/reflog_panel.go
+++ b/pkg/gui/reflog_panel.go
@@ -47,23 +47,30 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
return nil
}
+// the reflogs panel is the only panel where we cache data, in that we only
+// load entries that have been created since we last ran the call. This means
+// we need to be more careful with how we use this, and to ensure we're emptying
+// the reflogs array when changing contexts.
func (gui *Gui) refreshReflogCommits() error {
+ // pulling state into its own variable incase it gets swapped out for another state
+ // and we get an out of bounds exception
+ state := gui.State
var lastReflogCommit *commands.Commit
- if len(gui.State.ReflogCommits) > 0 {
- lastReflogCommit = gui.State.ReflogCommits[0]
+ if len(state.ReflogCommits) > 0 {
+ lastReflogCommit = state.ReflogCommits[0]
}
- commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, gui.State.FilterPath)
+ commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, state.FilterPath)
if err != nil {
return gui.surfaceError(err)
}
if onlyObtainedNewReflogCommits {
- gui.State.ReflogCommits = append(commits, gui.State.ReflogCommits...)
+ state.ReflogCommits = append(commits, state.ReflogCommits...)
} else {
// if we haven't found it we're probably in a new repo so we don't want to
// retain the old reflog commits
- gui.State.ReflogCommits = commits
+ state.ReflogCommits = commits
}
if gui.getCommitsView().Context == "reflog-commits" {