From 776d8f4d2e4afff3c80a16c33ad28780e41169e6 Mon Sep 17 00:00:00 2001 From: John Shin Date: Wed, 18 Jan 2023 08:14:03 -0800 Subject: [PATCH 1/3] refresh the staging panel on successful commit apply formatting --- pkg/gui/controllers.go | 4 ++++ pkg/integration/tests/commit/staged.go | 8 ++++++-- pkg/integration/tests/commit/staged_without_hooks.go | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index d7f6647c7..790a6d98b 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -9,6 +9,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" "github.com/jesseduffield/lazygit/pkg/gui/services/custom_commands" + "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/snake" ) @@ -92,6 +93,9 @@ func (gui *Gui) resetControllers() { onCommitSuccess := func() { gui.State.savedCommitMessage = "" + _ = gui.c.Refresh(types.RefreshOptions{ + Scope: []types.RefreshableView{types.STAGING}, + }) } commitMessageController := controllers.NewCommitMessageController( diff --git a/pkg/integration/tests/commit/staged.go b/pkg/integration/tests/commit/staged.go index 09bcf2815..f5e45995d 100644 --- a/pkg/integration/tests/commit/staged.go +++ b/pkg/integration/tests/commit/staged.go @@ -53,8 +53,12 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{ Contains(commitMessage), ) - t.Views().StagingSecondary().IsFocused() + t.Views().StagingSecondary(). + IsEmpty() - // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) + t.Views().Staging(). + IsFocused(). + Content(Contains("+myfile content")). + Content(DoesNotContain("+with a second line")) }, }) diff --git a/pkg/integration/tests/commit/staged_without_hooks.go b/pkg/integration/tests/commit/staged_without_hooks.go index 620f712f9..dcf20d08d 100644 --- a/pkg/integration/tests/commit/staged_without_hooks.go +++ b/pkg/integration/tests/commit/staged_without_hooks.go @@ -53,8 +53,12 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{ Contains("WIP" + commitMessage), ) - t.Views().StagingSecondary().IsFocused() + t.Views().StagingSecondary(). + IsEmpty() - // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) + t.Views().Staging(). + IsFocused(). + Content(Contains("+myfile content")). + Content(DoesNotContain("+with a second line")) }, }) From 40f6767cfc77931e35bc932b3adae943e7e521f0 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 13 Mar 2023 21:23:08 +0100 Subject: [PATCH 2/3] Avoid deactivating and activating when pushing the current context again When calling PushContext, do nothing if the context to be pushed is already on top of the stack. Avoids flicker in certain situations. --- pkg/gui/context.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index e4719ab13..bb69cc3ce 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 { @@ -105,7 +117,7 @@ func (gui *Gui) pushToContextStack(c types.Context) []types.Context { } } - return contextsToDeactivate + return contextsToDeactivate, c } func (gui *Gui) popContext() error { From b7c61aa883a5eddc2db6147cff9d13341b0936a8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 18 Mar 2023 10:58:16 +0100 Subject: [PATCH 3/3] Push initial context instead of just putting it in the context array This makes sure activateContext gets called on it. --- pkg/gui/gui.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 4e15af94e..4cf416389 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -64,9 +64,9 @@ type ContextManager struct { sync.RWMutex } -func NewContextManager(initialContext types.Context) ContextManager { +func NewContextManager() ContextManager { return ContextManager{ - ContextStack: []types.Context{initialContext}, + ContextStack: []types.Context{}, RWMutex: sync.RWMutex{}, } } @@ -299,11 +299,15 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) { }, ScreenMode: initialScreenMode, // TODO: put contexts in the context manager - ContextManager: NewContextManager(initialContext), + ContextManager: NewContextManager(), Contexts: contextTree, WindowViewNameMap: initialWindowViewNameMap, } + if err := gui.c.PushContext(initialContext); err != nil { + gui.c.Log.Error(err) + } + gui.RepoStateMap[Repo(currentDir)] = gui.State }