From 9adbef40de52c24d6604bf76bde0a8351b49bf39 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 29 Apr 2023 13:41:29 +1000 Subject: [PATCH] Refresh staging panel when committing We now refresh the staging panel when doing an unscoped refresh, so that if we commit from the staging panel we escape back to the files panel if need be. But that causes flickering when doing an unscoped refresh from other contexts, because the refreshStagingPanel function assumes that the staging panel has focus. So we're adding a guard at the top of that function to early exit if we don't have focus. --- pkg/gui/refresh.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index 2926152ed..5fd68dedc 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -85,6 +85,7 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error { types.REMOTES, types.STATUS, types.BISECT_INFO, + types.STAGING, }) } else { scopeSet = set.NewFromSlice(options.Scope) @@ -563,6 +564,13 @@ func (gui *Gui) refreshStatus() { func (gui *Gui) refreshStagingPanel(focusOpts types.OnFocusOpts) error { secondaryFocused := gui.secondaryStagingFocused() + mainFocused := gui.mainStagingFocused() + + // this method could be called when the staging panel is not being used, + // in which case we don't want to do anything. + if !mainFocused && !secondaryFocused { + return nil + } mainSelectedLineIdx := -1 secondarySelectedLineIdx := -1 @@ -647,6 +655,10 @@ func (gui *Gui) secondaryStagingFocused() bool { return gui.currentStaticContext().GetKey() == gui.State.Contexts.StagingSecondary.GetKey() } +func (gui *Gui) mainStagingFocused() bool { + return gui.currentStaticContext().GetKey() == gui.State.Contexts.Staging.GetKey() +} + func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error { selectedLineIdx := -1 if opts.ClickedWindowName == "main" {