From 114d3a5a25aa859b45fbb7e160bc0b34e37d15fb Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 5 Sep 2026 10:22:17 +0200 Subject: [PATCH] Render the focused main view again while it is being searched A refresh left the focused main view alone while a search was on, so the diff on screen stayed as it was however much the working tree had moved on underneath it. The search could not cope with the content changing under it, and leaving the content alone was the way around that. It can cope now. The positions are worked out again from whatever the view holds, and the status with them, so render it like any other. Co-authored-by: Claude Opus 5 (1M context) --- pkg/gui/view_helpers.go | 12 ++---- .../rerender_the_searched_main_view.go | 37 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 pkg/integration/tests/filter_and_search/rerender_the_searched_main_view.go diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 9b2e29c02..3d924a566 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -171,15 +171,9 @@ func (gui *Gui) postRefreshUpdate(c types.Context, opts types.OnFocusOpts) { currentCtx := gui.State.ContextMgr.Current() if currentCtx.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY || currentCtx.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY { - // Searching can't cope well with the view being updated while it is being searched. - // We might be able to fix the problems with this, but it doesn't seem easy, so for now - // just don't rerender the view while searching, on the assumption that users will probably - // either search or change their data, but not both at the same time. - if !currentCtx.GetView().IsSearching() { - sidePanelContext := gui.State.ContextMgr.NextInStack(currentCtx) - if sidePanelContext != nil && sidePanelContext.GetKey() == c.GetKey() { - sidePanelContext.HandleRenderToMain() - } + sidePanelContext := gui.State.ContextMgr.NextInStack(currentCtx) + if sidePanelContext != nil && sidePanelContext.GetKey() == c.GetKey() { + sidePanelContext.HandleRenderToMain() } } else if c.GetKey() == gui.State.ContextMgr.CurrentStatic().GetKey() { // If our view is not the current one, but it is the current static context, then this diff --git a/pkg/integration/tests/filter_and_search/rerender_the_searched_main_view.go b/pkg/integration/tests/filter_and_search/rerender_the_searched_main_view.go new file mode 100644 index 000000000..3d631e650 --- /dev/null +++ b/pkg/integration/tests/filter_and_search/rerender_the_searched_main_view.go @@ -0,0 +1,37 @@ +package filter_and_search + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RerenderTheSearchedMainView = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "A refresh renders the focused main view again even while it is being searched", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1", "one\ntwo\nthree\n") + shell.Commit("one") + + shell.UpdateFile("file1", "one\nNEEDLE\nthree\n") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + FilterOrSearch("NEEDLE"). + Content(Contains("+NEEDLE")). + Tap(func() { + t.Shell().UpdateFile("file1", "one\nOTHER\nthree\n") + }). + Press(keys.Universal.Refresh). + Content(Contains("+OTHER")). + Content(DoesNotContain("+NEEDLE")) + + t.Views().Search().Content(Contains("No matches for 'NEEDLE'")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 3d9edadfe..a4e732cf0 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -277,6 +277,7 @@ var tests = []*components.IntegrationTest{ filter_and_search.NestedFilter, filter_and_search.NestedFilterTransient, filter_and_search.NewSearch, + filter_and_search.RerenderTheSearchedMainView, filter_and_search.SearchALongDiff, filter_and_search.SearchStatusAfterARerender, filter_and_search.StageAllStagesOnlyTrackedFilesInTrackedOnlyFilter,