1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

ensure we retain state when returning to submodule parent

This commit is contained in:
Jesse Duffield
2022-02-13 11:35:42 +11:00
parent 94d66b267d
commit 943a8e83da
2 changed files with 20 additions and 5 deletions

View File

@@ -137,6 +137,12 @@ func (self *ViewContextMap) Set(viewName string, context types.Context) {
self.content[viewName] = context self.content[viewName] = context
} }
func (self *ViewContextMap) Entries() map[string]types.Context {
self.Lock()
defer self.Unlock()
return self.content
}
type TabContext struct { type TabContext struct {
Tab string Tab string
Contexts []types.Context Contexts []types.Context

View File

@@ -323,6 +323,8 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
if state := gui.RepoStateMap[Repo(currentDir)]; state != nil { if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
gui.State = state gui.State = state
gui.State.ViewsSetup = false gui.State.ViewsSetup = false
gui.syncViewContexts()
return
} }
} else { } else {
gui.c.Log.Error(err) gui.c.Log.Error(err)
@@ -341,11 +343,6 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
viewContextMap := context.NewViewContextMap() viewContextMap := context.NewViewContextMap()
for viewName, context := range initialViewContextMapping(contextTree) { for viewName, context := range initialViewContextMapping(contextTree) {
viewContextMap.Set(viewName, context) viewContextMap.Set(viewName, context)
view, err := gui.g.View(viewName)
if err != nil {
panic(err)
}
view.Context = string(context.GetKey())
} }
gui.State = &GuiRepoState{ gui.State = &GuiRepoState{
@@ -380,9 +377,21 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
Contexts: contextTree, Contexts: contextTree,
} }
gui.syncViewContexts()
gui.RepoStateMap[Repo(currentDir)] = gui.State 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 { func initialViewContextMapping(contextTree *context.ContextTree) map[string]types.Context {
return map[string]types.Context{ return map[string]types.Context{
"status": contextTree.Status, "status": contextTree.Status,