diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-03-24 19:13:00 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 19:13:00 +1100 |
commit | 4780953cef543bf506d3dc68547280dae2d1481b (patch) | |
tree | 21211912fb3919f6ece2c6b27f3927028376e939 /pkg/gui/context.go | |
parent | 11bc8b87faeba22b7afac550207cf54a66801641 (diff) | |
parent | b7c61aa883a5eddc2db6147cff9d13341b0936a8 (diff) |
Merge pull request #2377 from shinhs0506/clear-staging-after-commit
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r-- | pkg/gui/context.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 61de2d8dc..f097df807 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -52,7 +52,7 @@ func (gui *Gui) pushContext(c types.Context, opts types.OnFocusOpts) error { return nil } - contextsToDeactivate := gui.pushToContextStack(c) + contextsToDeactivate, contextToActivate := gui.pushToContextStack(c) for _, contextToDeactivate := range contextsToDeactivate { if err := gui.deactivateContext(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil { @@ -60,16 +60,28 @@ func (gui *Gui) pushContext(c types.Context, opts types.OnFocusOpts) error { } } - return gui.activateContext(c, opts) + if contextToActivate == nil { + return nil + } + + return gui.activateContext(contextToActivate, opts) } -// Adjusts the context stack based on the context that's being pushed and returns contexts to deactivate -func (gui *Gui) pushToContextStack(c types.Context) []types.Context { +// Adjusts the context stack based on the context that's being pushed and +// returns (contexts to deactivate, context to activate) +func (gui *Gui) pushToContextStack(c types.Context) ([]types.Context, types.Context) { contextsToDeactivate := []types.Context{} gui.State.ContextManager.Lock() defer gui.State.ContextManager.Unlock() + if len(gui.State.ContextManager.ContextStack) > 0 && + c == gui.State.ContextManager.ContextStack[len(gui.State.ContextManager.ContextStack)-1] { + // Context being pushed is already on top of the stack: nothing to + // deactivate or activate + return contextsToDeactivate, nil + } + if len(gui.State.ContextManager.ContextStack) == 0 { gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack, c) } else if c.GetKind() == types.SIDE_CONTEXT { @@ -108,7 +120,7 @@ func (gui *Gui) pushToContextStack(c types.Context) []types.Context { } } - return contextsToDeactivate + return contextsToDeactivate, c } func (gui *Gui) popContext() error { |