From 4981419ba95d0dc406a52c2938f28e89feba165c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 9 Jul 2025 15:12:03 +0200 Subject: [PATCH] Fix stale main view content when entering/exiting filtering view When entering filtering we would only call FocusLine, which takes care of highlighting the selected line in the commits list, but not of re-rendering the main view. HandleFocus does that. When exiting filtering, the HandleFocus call was missing entirely. The tests needed to be reworked a little bit to make this testable. --- pkg/gui/controllers/filtering_menu_action.go | 2 +- pkg/gui/controllers/helpers/mode_helper.go | 1 + .../keep_same_commit_selected_on_exit.go | 31 ++++++++++++++----- .../tests/filter_by_path/select_file.go | 15 +++++---- .../tests/filter_by_path/shared.go | 21 +++++++------ 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go index 6b67e009a..3a109a887 100644 --- a/pkg/gui/controllers/filtering_menu_action.go +++ b/pkg/gui/controllers/filtering_menu_action.go @@ -124,7 +124,7 @@ func (self *FilteringMenuAction) setFiltering() error { self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() { self.c.Contexts().LocalCommits.SetSelection(0) - self.c.Contexts().LocalCommits.FocusLine() + self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{}) }}) return nil diff --git a/pkg/gui/controllers/helpers/mode_helper.go b/pkg/gui/controllers/helpers/mode_helper.go index 4af1ddf3f..f90519e4d 100644 --- a/pkg/gui/controllers/helpers/mode_helper.go +++ b/pkg/gui/controllers/helpers/mode_helper.go @@ -178,6 +178,7 @@ func (self *ModeHelper) ClearFiltering() error { // before we entered filtering self.c.Contexts().LocalCommits.SelectCommitByHash(self.c.Modes().Filtering.GetSelectedCommitHash()) } + self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{}) }, }) return nil diff --git a/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go b/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go index 728a5aedf..76f35650a 100644 --- a/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go +++ b/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go @@ -19,9 +19,9 @@ var KeepSameCommitSelectedOnExit = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains(`none of the two`).IsSelected(), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`), + Contains(`only otherFile`), + Contains(`only filterFile`), ).Press(keys.Universal.FilteringMenu). Tap(func() { t.ExpectPopup().Menu(). @@ -36,16 +36,33 @@ var KeepSameCommitSelectedOnExit = NewIntegrationTest(NewIntegrationTestArgs{ ConfirmFirstSuggestion() }). Lines( - Contains(`only filterFile`).IsSelected(), - Contains(`both files`), + Contains(`both files`).IsSelected(), + Contains(`only filterFile`), ). - SelectNextItem(). + Tap(func() { + t.Views().Main(). + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + ) + }). PressEscape(). Lines( Contains(`none of the two`), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`).IsSelected(), + Contains(`only otherFile`), + Contains(`only filterFile`), + ) + + t.Views().Main(). + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" otherFile | 2 +-"), + Equals(" 2 files changed, 2 insertions(+), 2 deletions(-)"), ) }, }) diff --git a/pkg/integration/tests/filter_by_path/select_file.go b/pkg/integration/tests/filter_by_path/select_file.go index 13454e1e8..a01081a22 100644 --- a/pkg/integration/tests/filter_by_path/select_file.go +++ b/pkg/integration/tests/filter_by_path/select_file.go @@ -19,22 +19,25 @@ var SelectFile = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains(`none of the two`).IsSelected(), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`), + Contains(`only otherFile`), + Contains(`only filterFile`), ). - NavigateToLine(Contains(`only filterFile`)). + NavigateToLine(Contains(`both files`)). PressEnter() - // when you click into the commit itself, you see all files from that commit t.Views().CommitFiles(). IsFocused(). Lines( - Contains(`filterFile`).IsSelected(), + Equals(`▼ /`).IsSelected(), + Equals(` M filterFile`), + Equals(` M otherFile`), ). + SelectNextItem(). Press(keys.Universal.FilteringMenu) - t.ExpectPopup().Menu().Title(Equals("Filtering")).Select(Contains("Filter by 'filterFile'")).Confirm() + t.ExpectPopup().Menu().Title(Equals("Filtering")). + Select(Contains("Filter by 'filterFile'")).Confirm() postFilterTest(t) }, diff --git a/pkg/integration/tests/filter_by_path/shared.go b/pkg/integration/tests/filter_by_path/shared.go index 6fec20a3e..dd2538a9c 100644 --- a/pkg/integration/tests/filter_by_path/shared.go +++ b/pkg/integration/tests/filter_by_path/shared.go @@ -6,14 +6,13 @@ import ( func commonSetup(shell *Shell) { shell.CreateFileAndAdd("filterFile", "original filterFile content") + shell.Commit("only filterFile") shell.CreateFileAndAdd("otherFile", "original otherFile content") - shell.Commit("both files") - - shell.UpdateFileAndAdd("otherFile", "new otherFile content") shell.Commit("only otherFile") + shell.UpdateFileAndAdd("otherFile", "new otherFile content") shell.UpdateFileAndAdd("filterFile", "new filterFile content") - shell.Commit("only filterFile") + shell.Commit("both files") shell.EmptyCommit("none of the two") } @@ -24,14 +23,18 @@ func postFilterTest(t *TestDriver) { t.Views().Commits(). IsFocused(). Lines( - Contains(`only filterFile`).IsSelected(), - Contains(`both files`), - ). - SelectNextItem() + Contains(`both files`).IsSelected(), + Contains(`only filterFile`), + ) // we only show the filtered file's changes in the main view t.Views().Main(). - Content(Contains("filterFile").DoesNotContain("otherFile")) + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + ) t.Views().Commits(). PressEnter()