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 60ce9b580..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 @@ -41,13 +41,33 @@ 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(), + Contains("new-branch"), + ) + + t.Views().Branches(). + Focus(). // cancel the filter PressEscape(). Lines( Contains("checked-out-branch").IsSelected(), Contains("other"), Contains("master"), + Contains("new-branch"), ) }, })