From 5e65e8e0eaf61085dc8f2001c94531417c27a276 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 11 Jul 2025 15:18:40 +0200 Subject: [PATCH] Refresh all affected scopes when entering/exiting filtering Since filtering switches to half-screen mode in the local commits panel, most people probably didn't notice, but we do also filter those other views. So when leaving half-screen mode (but not filtering), you could switch to sub-commits or stashes, and those would show the filtered view only after the next refresh (e.g. after a background fetch). It's worse when leaving filtering, because this goes back to normal screen mode, and you would often see an empty stashes panel after that (until the next background fetch), which is quite confusing. I also find it questionable to always switch focus to the commits panel when entering filtering. If it is initiated from subcommits, reflog, or stashes, maybe we want to stay there. I'm not changing this now since I'm unsure how much people rely on the current behavior. --- pkg/gui/controllers/filtering_menu_action.go | 3 ++- pkg/gui/controllers/helpers/mode_helper.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go index 3a109a887..2ed072676 100644 --- a/pkg/gui/controllers/filtering_menu_action.go +++ b/pkg/gui/controllers/filtering_menu_action.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -122,7 +123,7 @@ func (self *FilteringMenuAction) setFiltering() error { self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{}) - self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() { + self.c.Refresh(types.RefreshOptions{Scope: helpers.ScopesToRefreshWhenFilteringModeChanges(), Then: func() { self.c.Contexts().LocalCommits.SetSelection(0) self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{}) }}) diff --git a/pkg/gui/controllers/helpers/mode_helper.go b/pkg/gui/controllers/helpers/mode_helper.go index a5960697a..702825c58 100644 --- a/pkg/gui/controllers/helpers/mode_helper.go +++ b/pkg/gui/controllers/helpers/mode_helper.go @@ -168,7 +168,7 @@ func (self *ModeHelper) ClearFiltering() error { } self.c.Refresh(types.RefreshOptions{ - Scope: []types.RefreshableView{types.COMMITS}, + Scope: ScopesToRefreshWhenFilteringModeChanges(), Then: func() { // Find the commit that was last selected in filtering mode, and select it again after refreshing if !self.c.Contexts().LocalCommits.SelectCommitByHash(selectedCommitHash) { @@ -185,6 +185,17 @@ func (self *ModeHelper) ClearFiltering() error { return nil } +// Stashes really only need to be refreshed when filtering by path, not by author, but it's too much +// work to distinguish this, and refreshing stashes is fast, so we don't bother +func ScopesToRefreshWhenFilteringModeChanges() []types.RefreshableView { + return []types.RefreshableView{ + types.COMMITS, + types.SUB_COMMITS, + types.REFLOG, + types.STASH, + } +} + func (self *ModeHelper) SetSuppressRebasingMode(value bool) { self.suppressRebasingMode = value }