Exercise patch-move selection recovery through the diff

The commit rewrite triggered by moving a custom patch must keep the
user's place without relying on the patch-building panel. Build the
patch and leave the affected range selected in the focused diff so the
regression test follows the UI that survives this branch.

Co-Authored-By: GitHub Copilot <copilot@github.com>
This commit is contained in:
Stefan Haller
2026-10-05 11:20:32 +02:00
co-authored by GitHub Copilot
parent 935f863930
commit bdbdd4286e
2 changed files with 12 additions and 21 deletions
@@ -1,12 +1,12 @@
package patch_building
package main_view
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var KeepSelectionAfterMovingPatchOutMainView = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Moving a custom patch out of a commit leaves the focused main view's selection on a change that is still there, rather than painted over the diff the rewrite left behind",
var KeepSelectionAfterMovingPatchOut = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Moving a custom patch out of a commit leaves the focused main view's selection on a change that is still there",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
@@ -28,12 +28,12 @@ var KeepSelectionAfterMovingPatchOutMainView = NewIntegrationTest(NewIntegration
).
PressEnter()
// Take the first of the commit's three changed lines into a custom patch.
t.Views().CommitFiles().
IsFocused().
PressEnter()
Press(keys.Universal.FocusMainView)
t.Views().PatchBuilding().
// Take the first modification into a custom patch.
t.Views().Main().
IsFocused().
SelectedLines(
Contains("-one"),
@@ -44,21 +44,13 @@ var KeepSelectionAfterMovingPatchOutMainView = NewIntegrationTest(NewIntegration
Contains("-one"),
Contains("+ONE"),
).
PressPrimaryAction().
Press(keys.Universal.Return)
// Leave a range selected over the diff, spanning the lines the patch holds. The
// patch move doesn't go through the main view at all, so without a net nothing
// would move this selection off lines that the rewrite takes away.
t.Views().CommitFiles().
IsFocused().
Press(keys.Universal.FocusMainView)
PressPrimaryAction()
// Keep a range selected across lines that the pending patch will remove from
// the commit and a later change that will remain.
t.Views().Main().
IsFocused().
SelectedLines(
Contains("-one"),
).
NavigateToLine(Contains("-one")).
Press(keys.Universal.ToggleRangeSelect).
NavigateToLine(Contains("+THREE")).
SelectedLines(
@@ -72,8 +64,7 @@ var KeepSelectionAfterMovingPatchOutMainView = NewIntegrationTest(NewIntegration
t.Common().SelectPatchOption(Contains("Move patch out into index"))
// The moved lines are gone from the commit, so the range collapses onto the
// change that has taken its place — the same place in the diff's changes, which
// is where the user was.
// change that has taken their place.
t.Views().Main().
IsFocused().
Content(DoesNotContain("+ONE")).
+1 -1
View File
@@ -407,6 +407,7 @@ var tests = []*components.IntegrationTest{
main_view.KeepPositionWhenTheSelectionIsOffScreen,
main_view.KeepScrollWhenTheDiffCantBeRead,
main_view.KeepSelectedRangeWhenChangingContextSize,
main_view.KeepSelectionAfterMovingPatchOut,
main_view.KeepSelectionVisibleWhenDiffShrinks,
main_view.MoveOnWhenThePatchMarksRewrapTheDiff,
main_view.NavigateByHunkAndFile,
@@ -473,7 +474,6 @@ var tests = []*components.IntegrationTest{
patch_building.CopyRenamedFileDiff,
patch_building.DiscardLinesFromCommit,
patch_building.EditLineInPatchBuildingPanel,
patch_building.KeepSelectionAfterMovingPatchOutMainView,
patch_building.MoveRangeToIndex,
patch_building.MoveToEarlierCommit,
patch_building.MoveToEarlierCommitFromAddedFile,