From f15be327564e2d9716a952a63854b7ddf0cdb1d9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 25 Mar 2025 12:30:08 +0100 Subject: [PATCH] Always render diffs to the main/secondary context pair, even for files Previously we would render the diff for a directory to the main/secondary pair, but a diff for a file to the staging/stagingSecondary pair. (And similar for commit files: main/secondary for directories, but patchBuilding/patchBuildingSecondary for files.) I always found this confusing and couldn't really understand why we are doing this; but now it gets in my way because I want to attach a controller to main/secondary so that they can be focused. So change it to always use the main context pair for everything we render from a side panel. --- .../controllers/commits_files_controller.go | 9 ++------- pkg/gui/controllers/files_controller.go | 19 +------------------ pkg/integration/tests/patch_building/apply.go | 2 +- .../tests/patch_building/apply_in_reverse.go | 2 +- .../apply_in_reverse_with_conflict.go | 4 ++-- .../patch_building/move_range_to_index.go | 4 ++-- .../tests/patch_building/move_to_index.go | 2 +- .../patch_building/move_to_index_partial.go | 2 +- ..._to_index_works_even_if_noprefix_is_set.go | 2 +- .../patch_building/remove_from_commit.go | 2 +- .../tests/stash/stash_staged_partial_file.go | 3 ++- 11 files changed, 15 insertions(+), 36 deletions(-) diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 77037513e..6f28f85e0 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -138,7 +138,7 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] func (self *CommitFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return []*gocui.ViewMouseBinding{ { - ViewName: "patchBuilding", + ViewName: "main", Key: gocui.MouseLeft, Handler: self.onClickMain, FocusedView: self.context().GetViewName(), @@ -163,13 +163,8 @@ func (self *CommitFilesController) GetOnRenderToMain() func() { cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, node.GetPath(), false) task := types.NewRunPtyTask(cmdObj.GetCmd()) - pair := self.c.MainViewPairs().Normal - if node.File != nil { - pair = self.c.MainViewPairs().PatchBuilding - } - self.c.RenderToMainViews(types.RefreshMainOpts{ - Pair: pair, + Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ Title: self.c.Tr.Patch, SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 167e29f1b..abb2dd788 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -214,12 +214,6 @@ func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []* Handler: self.onClickMain, FocusedView: self.context().GetViewName(), }, - { - ViewName: "patchBuilding", - Key: gocui.MouseLeft, - Handler: self.onClickMain, - FocusedView: self.context().GetViewName(), - }, { ViewName: "mergeConflicts", Key: gocui.MouseLeft, @@ -232,12 +226,6 @@ func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []* Handler: self.onClickSecondary, FocusedView: self.context().GetViewName(), }, - { - ViewName: "patchBuildingSecondary", - Key: gocui.MouseLeft, - Handler: self.onClickSecondary, - FocusedView: self.context().GetViewName(), - }, } } @@ -304,11 +292,6 @@ func (self *FilesController) GetOnRenderToMain() func() { self.c.Helpers().MergeConflicts.ResetMergeState() - pair := self.c.MainViewPairs().Normal - if node.File != nil { - pair = self.c.MainViewPairs().Staging - } - split := self.c.UserConfig().Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) mainShowsStaged := !split && node.GetHasStagedChanges() @@ -318,7 +301,7 @@ func (self *FilesController) GetOnRenderToMain() func() { title = self.c.Tr.StagedChanges } refreshOpts := types.RefreshMainOpts{ - Pair: pair, + Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ Task: types.NewRunPtyTask(cmdObj.GetCmd()), SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), diff --git a/pkg/integration/tests/patch_building/apply.go b/pkg/integration/tests/patch_building/apply.go index 8774f07d7..533ad1e23 100644 --- a/pkg/integration/tests/patch_building/apply.go +++ b/pkg/integration/tests/patch_building/apply.go @@ -48,7 +48,7 @@ var Apply = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content(Contains("second line")) + t.Views().Secondary().Content(Contains("second line")) t.Common().SelectPatchOption(MatchesRegexp(`Apply patch$`)) diff --git a/pkg/integration/tests/patch_building/apply_in_reverse.go b/pkg/integration/tests/patch_building/apply_in_reverse.go index f15d4c35c..f2aa6b3a8 100644 --- a/pkg/integration/tests/patch_building/apply_in_reverse.go +++ b/pkg/integration/tests/patch_building/apply_in_reverse.go @@ -35,7 +35,7 @@ var ApplyInReverse = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content(Contains("+file1 content")) + t.Views().Secondary().Content(Contains("+file1 content")) t.Common().SelectPatchOption(Contains("Apply patch in reverse")) diff --git a/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go index 78367cc84..1a09cea7a 100644 --- a/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go +++ b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go @@ -44,13 +44,13 @@ var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{ Tap(func() { t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content( + t.Views().Secondary().Content( Contains("+more file1 content")) }). SelectNextItem(). PressPrimaryAction() - t.Views().PatchBuildingSecondary().Content( + t.Views().Secondary().Content( Contains("+more file1 content").Contains("+more file2 content")) t.Common().SelectPatchOption(Contains("Apply patch in reverse")) diff --git a/pkg/integration/tests/patch_building/move_range_to_index.go b/pkg/integration/tests/patch_building/move_range_to_index.go index fbacb50a5..c8d379c97 100644 --- a/pkg/integration/tests/patch_building/move_range_to_index.go +++ b/pkg/integration/tests/patch_building/move_range_to_index.go @@ -43,8 +43,8 @@ var MoveRangeToIndex = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content(Contains("second line")) - t.Views().PatchBuildingSecondary().Content(Contains("file two content")) + t.Views().Secondary().Content(Contains("second line")) + t.Views().Secondary().Content(Contains("file two content")) t.Common().SelectPatchOption(MatchesRegexp(`Move patch out into index$`)) diff --git a/pkg/integration/tests/patch_building/move_to_index.go b/pkg/integration/tests/patch_building/move_to_index.go index af2e867c7..6eca8865f 100644 --- a/pkg/integration/tests/patch_building/move_to_index.go +++ b/pkg/integration/tests/patch_building/move_to_index.go @@ -35,7 +35,7 @@ var MoveToIndex = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content(Contains("+file1 content")) + t.Views().Secondary().Content(Contains("+file1 content")) t.Common().SelectPatchOption(Contains("Move patch out into index")) diff --git a/pkg/integration/tests/patch_building/move_to_index_partial.go b/pkg/integration/tests/patch_building/move_to_index_partial.go index f35155202..827a3aedb 100644 --- a/pkg/integration/tests/patch_building/move_to_index_partial.go +++ b/pkg/integration/tests/patch_building/move_to_index_partial.go @@ -53,7 +53,7 @@ var MoveToIndexPartial = NewIntegrationTest(NewIntegrationTestArgs{ Tap(func() { t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary(). + t.Views().Secondary(). ContainsLines( Contains(`-first line`), Contains(`+first line2`), diff --git a/pkg/integration/tests/patch_building/move_to_index_works_even_if_noprefix_is_set.go b/pkg/integration/tests/patch_building/move_to_index_works_even_if_noprefix_is_set.go index 391223c60..8c2ba84b0 100644 --- a/pkg/integration/tests/patch_building/move_to_index_works_even_if_noprefix_is_set.go +++ b/pkg/integration/tests/patch_building/move_to_index_works_even_if_noprefix_is_set.go @@ -33,7 +33,7 @@ var MoveToIndexWorksEvenIfNoprefixIsSet = NewIntegrationTest(NewIntegrationTestA ). PressPrimaryAction() - t.Views().PatchBuildingSecondary().Content(Contains("+file1 content")) + t.Views().Secondary().Content(Contains("+file1 content")) t.Common().SelectPatchOption(Contains("Move patch out into index")) diff --git a/pkg/integration/tests/patch_building/remove_from_commit.go b/pkg/integration/tests/patch_building/remove_from_commit.go index bfa0925d6..fbd78fcf7 100644 --- a/pkg/integration/tests/patch_building/remove_from_commit.go +++ b/pkg/integration/tests/patch_building/remove_from_commit.go @@ -35,7 +35,7 @@ var RemoveFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(Contains("Building patch")) - t.Views().PatchBuildingSecondary().Content(Contains("+file1 content")) + t.Views().Secondary().Content(Contains("+file1 content")) t.Common().SelectPatchOption(Contains("Remove patch from original commit")) diff --git a/pkg/integration/tests/stash/stash_staged_partial_file.go b/pkg/integration/tests/stash/stash_staged_partial_file.go index 8219b55d3..5337eaee2 100644 --- a/pkg/integration/tests/stash/stash_staged_partial_file.go +++ b/pkg/integration/tests/stash/stash_staged_partial_file.go @@ -58,11 +58,12 @@ var StashStagedPartialFile = NewIntegrationTest(NewIntegrationTestArgs{ ) t.Views().Files(). + Focus(). Lines( Contains("file-staged"), ) - t.Views().Staging(). + t.Views().Main(). Content( Contains(" line1\n line2\n line3\n-line4\n+line4 mod"), )