Skip to content

Commit 2f9e4ed

Browse files
committed
feature: auto select the next change after discarding one (#2704)
Signed-off-by: leo <longshuang@msn.cn>
1 parent c3315a9 commit 2f9e4ed

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/ViewModels/Discard.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public Discard(Repository repo)
5555
Mode = new DiscardAllMode();
5656
}
5757

58-
public Discard(Repository repo, List<Models.Change> changes)
58+
public Discard(Repository repo, List<Models.Change> changes, Models.Change next)
5959
{
6060
_repo = repo;
6161
_changes = changes;
62+
_next = next;
6263

6364
if (_changes == null)
6465
Mode = new DiscardAllMode();
@@ -87,11 +88,17 @@ public override async Task<bool> Sure()
8788
}
8889

8990
log.Complete();
91+
92+
var selection = new ChangeSelection(null);
93+
if (_next != null)
94+
selection.Changes.Add(_next);
95+
_repo.WorkingCopy.SelectedUnstaged = selection;
9096
_repo.MarkWorkingCopyDirtyManually();
9197
return true;
9298
}
9399

94100
private readonly Repository _repo = null;
95101
private readonly List<Models.Change> _changes = null;
102+
private readonly Models.Change _next = null;
96103
}
97104
}

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ public void DiscardAllChanges()
414414
_repo.ShowPopup(new Discard(_repo));
415415
}
416416

417-
public void Discard(List<Models.Change> changes)
417+
public void Discard(List<Models.Change> changes, Models.Change next)
418418
{
419419
if (_repo.CanCreatePopup())
420-
_repo.ShowPopup(new Discard(_repo, changes));
420+
_repo.ShowPopup(new Discard(_repo, changes, next));
421421
}
422422

423423
public void ClearFilter()

src/Views/WorkingCopy.axaml.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ private async void OnUnstagedKeyDown(object _, KeyEventArgs e)
9999
}
100100
else if (e.Key is Key.Delete or Key.Back)
101101
{
102-
vm.Discard(changes);
102+
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
103+
vm.Discard(changes, next);
103104
e.Handled = true;
104105
}
105106
else if (e.Key is Key.O && e.KeyModifiers == cmdKey && changes.Count == 1)
@@ -413,7 +414,8 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.Repository re
413414
stage.Tag = "Enter/Space";
414415
stage.Click += async (_, e) =>
415416
{
416-
await vm.StageChangesAsync(changes, null);
417+
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
418+
await vm.StageChangesAsync(changes, next);
417419
e.Handled = true;
418420
};
419421

@@ -423,7 +425,8 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.Repository re
423425
discard.Tag = "Back/Delete";
424426
discard.Click += (_, e) =>
425427
{
426-
vm.Discard(changes);
428+
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
429+
vm.Discard(changes, next);
427430
e.Handled = true;
428431
};
429432

@@ -818,7 +821,8 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.Repository re
818821
stage.Tag = "Enter/Space";
819822
stage.Click += async (_, e) =>
820823
{
821-
await vm.StageChangesAsync(changes, null);
824+
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
825+
await vm.StageChangesAsync(changes, next);
822826
e.Handled = true;
823827
};
824828

@@ -828,7 +832,8 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.Repository re
828832
discard.Tag = "Back/Delete";
829833
discard.Click += (_, e) =>
830834
{
831-
vm.Discard(changes);
835+
var next = UnstagedChangesView.GetNextChangeWithoutSelection();
836+
vm.Discard(changes, next);
832837
e.Handled = true;
833838
};
834839

@@ -1020,7 +1025,8 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.Repository repo,
10201025
unstage.Tag = "Enter/Space";
10211026
unstage.Click += async (_, e) =>
10221027
{
1023-
await vm.UnstageChangesAsync(changes, null);
1028+
var next = StagedChangesView.GetNextChangeWithoutSelection();
1029+
await vm.UnstageChangesAsync(changes, next);
10241030
e.Handled = true;
10251031
};
10261032

@@ -1234,7 +1240,8 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.Repository repo,
12341240
unstage.Tag = "Enter/Space";
12351241
unstage.Click += async (_, e) =>
12361242
{
1237-
await vm.UnstageChangesAsync(changes, null);
1243+
var next = StagedChangesView.GetNextChangeWithoutSelection();
1244+
await vm.UnstageChangesAsync(changes, next);
12381245
e.Handled = true;
12391246
};
12401247

0 commit comments

Comments
 (0)