Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/ViewModels/WorkingCopy.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Avalonia.Controls;
Expand Down Expand Up @@ -322,8 +323,9 @@ public void StashAll(bool autoStart)

public void StageSelected()
{
var nextSelection = CalculateNextSelection(_selectedUnstaged, Unstaged);
StageChanges(_selectedUnstaged);
SelectedUnstaged = [];
SelectedUnstaged = nextSelection;
}

public void StageAll()
Expand Down Expand Up @@ -359,8 +361,9 @@ public async void StageChanges(List<Models.Change> changes)

public void UnstageSelected()
{
var nextSelection = CalculateNextSelection(_selectedStaged, Staged);
UnstageChanges(_selectedStaged);
SelectedStaged = [];
SelectedStaged = nextSelection;
}

public void UnstageAll()
Expand Down Expand Up @@ -1357,6 +1360,19 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
return false;
}

private static List<Models.Change> CalculateNextSelection(List<Models.Change> selected, List<Models.Change> all)
{
var indices = selected.Select(x => all.IndexOf(x)).ToArray();
var min = indices.Min();
var next = min + 1;
while (indices.Contains(next))
next++;
if (next >= all.Count)
next = min - 1;
List<Models.Change> nextSelection = next >= 0 ? [all[next]] : [];
return nextSelection;
}

private Repository _repo = null;
private bool _isLoadingData = false;
private bool _isStaging = false;
Expand Down