summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-05 13:22:03 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-06 19:34:32 +1000
commit7178bab6b4539f43f0dbf61549629380a8c5148d (patch)
tree06885068308f423815b541e1efc42e4fd20c4d74
parent2d7452bfaa519cf349f457c1123a4a15cca5eaed (diff)
only re-use repo state when jumping in and out of submodules
-rw-r--r--pkg/gui/gui.go30
-rw-r--r--pkg/gui/quitting.go2
-rw-r--r--pkg/gui/recent_repos_panel.go6
-rw-r--r--pkg/gui/submodules_panel.go2
4 files changed, 26 insertions, 14 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index f2e846660..a3de9ca93 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -352,16 +352,28 @@ type guiState struct {
ViewsSetup bool
}
-func (gui *Gui) resetState(filterPath string) {
+// reuseState determines if we pull the repo state from our repo state map or
+// just re-initialize it. For now we're only re-using state when we're going
+// in and out of submodules, for the sake of having the cursor back on the submodule
+// when we return.
+//
+// I tried out always reverting to the repo's original state but found that in fact
+// it gets a bit confusing to land back in the status panel when visiting a repo
+// you've already switched from. There's no doubt some easy way to make the UX
+// optimal for all cases but I'm too lazy to think about what that is right now
+func (gui *Gui) resetState(filterPath string, reuseState bool) {
currentDir, err := os.Getwd()
- if err == nil {
- if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
- gui.State = state
- gui.State.ViewsSetup = false
- return
+
+ if reuseState {
+ if err == nil {
+ if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
+ gui.State = state
+ gui.State.ViewsSetup = false
+ return
+ }
+ } else {
+ gui.Log.Error(err)
}
- } else {
- gui.Log.Error(err)
}
showTree := gui.Config.GetUserConfig().Gui.ShowFileTree
@@ -443,7 +455,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
RepoStateMap: map[Repo]*guiState{},
}
- gui.resetState(filterPath)
+ gui.resetState(filterPath, false)
gui.watchFilesForChanges()
diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go
index 778db1a61..24b92efc2 100644
--- a/pkg/gui/quitting.go
+++ b/pkg/gui/quitting.go
@@ -57,7 +57,7 @@ func (gui *Gui) handleTopLevelReturn() error {
gui.RepoPathStack = repoPathStack[:n]
- return gui.dispatchSwitchToRepo(path)
+ return gui.dispatchSwitchToRepo(path, true)
}
if gui.Config.GetUserConfig().QuitOnTopLevelReturn {
diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go
index eecd0e11f..eb646a752 100644
--- a/pkg/gui/recent_repos_panel.go
+++ b/pkg/gui/recent_repos_panel.go
@@ -28,7 +28,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
// if we were in a submodule, we want to forget about that stack of repos
// so that hitting escape in the new repo does nothing
gui.RepoPathStack = []string{}
- return gui.dispatchSwitchToRepo(path)
+ return gui.dispatchSwitchToRepo(path, false)
},
}
}
@@ -50,7 +50,7 @@ func (gui *Gui) handleShowAllBranchLogs() error {
})
}
-func (gui *Gui) dispatchSwitchToRepo(path string) error {
+func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
env.UnsetGitDirEnvs()
originalPath, err := os.Getwd()
if err != nil {
@@ -87,7 +87,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string) error {
gui.Mutexes.RefreshingFilesMutex.Lock()
defer gui.Mutexes.RefreshingFilesMutex.Unlock()
- gui.resetState("")
+ gui.resetState("", reuse)
return nil
})
diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go
index 261d8af20..5be2bd63f 100644
--- a/pkg/gui/submodules_panel.go
+++ b/pkg/gui/submodules_panel.go
@@ -73,7 +73,7 @@ func (gui *Gui) enterSubmodule(submodule *models.SubmoduleConfig) error {
}
gui.RepoPathStack = append(gui.RepoPathStack, wd)
- return gui.dispatchSwitchToRepo(submodule.Path)
+ return gui.dispatchSwitchToRepo(submodule.Path, true)
}
func (gui *Gui) removeSubmodule(submodule *models.SubmoduleConfig) error {