diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-13 11:35:42 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 943a8e83da2f5ab9afc7dc22f32bfb4609ff6347 (patch) | |
tree | eaff66f536fbb72cf30ea4fd2f8c756c5cbbf342 | |
parent | 94d66b267dc4c5c415887566dcceb8e267d4ff06 (diff) |
ensure we retain state when returning to submodule parent
-rw-r--r-- | pkg/gui/context/context.go | 6 | ||||
-rw-r--r-- | pkg/gui/gui.go | 19 |
2 files changed, 20 insertions, 5 deletions
diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go index 5f7c8f163..e33a6c253 100644 --- a/pkg/gui/context/context.go +++ b/pkg/gui/context/context.go @@ -137,6 +137,12 @@ func (self *ViewContextMap) Set(viewName string, context types.Context) { self.content[viewName] = context } +func (self *ViewContextMap) Entries() map[string]types.Context { + self.Lock() + defer self.Unlock() + return self.content +} + type TabContext struct { Tab string Contexts []types.Context diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 7dab1dc99..84203c9e5 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -323,6 +323,8 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) { if state := gui.RepoStateMap[Repo(currentDir)]; state != nil { gui.State = state gui.State.ViewsSetup = false + gui.syncViewContexts() + return } } else { gui.c.Log.Error(err) @@ -341,11 +343,6 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) { viewContextMap := context.NewViewContextMap() for viewName, context := range initialViewContextMapping(contextTree) { viewContextMap.Set(viewName, context) - view, err := gui.g.View(viewName) - if err != nil { - panic(err) - } - view.Context = string(context.GetKey()) } gui.State = &GuiRepoState{ @@ -380,9 +377,21 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) { Contexts: contextTree, } + gui.syncViewContexts() + gui.RepoStateMap[Repo(currentDir)] = gui.State } +func (gui *Gui) syncViewContexts() { + for viewName, context := range gui.State.ViewContextMap.Entries() { + view, err := gui.g.View(viewName) + if err != nil { + panic(err) + } + view.Context = string(context.GetKey()) + } +} + func initialViewContextMapping(contextTree *context.ContextTree) map[string]types.Context { return map[string]types.Context{ "status": contextTree.Status, |