From c6df856079a80b2e5d178238d2622901c7487cba Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 10 Jun 2024 11:19:54 +0200 Subject: [PATCH 1/2] Add test demonstrating a problem with updating the filter when the model changes We only update the filter when the filtered view has the focus. --- .../filter_updates_when_model_changes.go | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go b/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go index 60ce9b580..950decc14 100644 --- a/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go +++ b/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go @@ -41,13 +41,35 @@ var FilterUpdatesWhenModelChanges = NewIntegrationTest(NewIntegrationTestArgs{ }). Lines( Contains("checked-out-branch").IsSelected(), - ). + ) + + // Verify that updating the filter works even if the view is not the active one + t.Views().Files().Focus() + + // To do that, we use a custom command to create a new branch that matches the filter + t.GlobalPress(keys.Universal.ExecuteCustomCommand) + t.ExpectPopup().Prompt(). + Title(Equals("Custom command:")). + Type("git branch new-branch"). + Confirm() + + t.Views().Branches(). + Lines( + Contains("checked-out-branch").IsSelected(), + /* EXPECTED: + Contains("new-branch"), + */ + ) + + t.Views().Branches(). + Focus(). // cancel the filter PressEscape(). Lines( Contains("checked-out-branch").IsSelected(), Contains("other"), Contains("master"), + Contains("new-branch"), ) }, }) From e205c6ba7f65e566eeee0a08c08cde245a0493f9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 10 Jun 2024 11:20:59 +0200 Subject: [PATCH 2/2] Always reapply filters on filtered views, even inactive ones --- pkg/gui/controllers/helpers/search_helper.go | 10 +++++----- .../filter_updates_when_model_changes.go | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go index 2cffe418b..653640e02 100644 --- a/pkg/gui/controllers/helpers/search_helper.go +++ b/pkg/gui/controllers/helpers/search_helper.go @@ -239,14 +239,14 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) { } func (self *SearchHelper) ReApplyFilter(context types.Context) { - state := self.searchState() - if context == state.Context { - filterableContext, ok := context.(types.IFilterableContext) - if ok { + filterableContext, ok := context.(types.IFilterableContext) + if ok { + state := self.searchState() + if context == state.Context { filterableContext.SetSelection(0) _ = filterableContext.GetView().SetOriginY(0) - filterableContext.ReApplyFilter(self.c.UserConfig.Gui.UseFuzzySearch()) } + filterableContext.ReApplyFilter(self.c.UserConfig.Gui.UseFuzzySearch()) } } diff --git a/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go b/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go index 950decc14..eb98f730e 100644 --- a/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go +++ b/pkg/integration/tests/filter_and_search/filter_updates_when_model_changes.go @@ -56,9 +56,7 @@ var FilterUpdatesWhenModelChanges = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Branches(). Lines( Contains("checked-out-branch").IsSelected(), - /* EXPECTED: Contains("new-branch"), - */ ) t.Views().Branches().