From af97bf484cd8eaba64b7fd4a10aed36d1f5f0690 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/controllers/helpers/refresh_helper.go | 1 + pkg/gui/controllers/helpers/staging_helper.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 2c3bc4c91..354a2115b 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -80,6 +80,7 @@ func (self *RefreshHelper) Refresh(options types.RefreshOptions) error { types.REMOTES, types.STATUS, types.BISECT_INFO, + types.STAGING, }) } else { scopeSet = set.NewFromSlice(options.Scope) diff --git a/pkg/gui/controllers/helpers/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index da67de9b8..75280b985 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -21,6 +21,13 @@ func NewStagingHelper( // NOTE: used from outside this file func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) error { secondaryFocused := self.secondaryStagingFocused() + mainFocused := self.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 @@ -109,3 +116,7 @@ func (self *StagingHelper) handleStagingEscape() error { func (self *StagingHelper) secondaryStagingFocused() bool { return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().StagingSecondary.GetKey() } + +func (self *StagingHelper) mainStagingFocused() bool { + return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().Staging.GetKey() +}