mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 12:55:00 +00:00
Automatically select next change after (un)stage
This commit is contained in:
parent
b1457fe39d
commit
07be7d7d0f
1 changed files with 18 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Controls;
|
||||
|
@ -322,8 +323,9 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void StageSelected()
|
||||
{
|
||||
var nextSelection = CalculateNextSelection(_selectedUnstaged, Unstaged);
|
||||
StageChanges(_selectedUnstaged);
|
||||
SelectedUnstaged = [];
|
||||
SelectedUnstaged = nextSelection;
|
||||
}
|
||||
|
||||
public void StageAll()
|
||||
|
@ -359,8 +361,9 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void UnstageSelected()
|
||||
{
|
||||
var nextSelection = CalculateNextSelection(_selectedStaged, Staged);
|
||||
UnstageChanges(_selectedStaged);
|
||||
SelectedStaged = [];
|
||||
SelectedStaged = nextSelection;
|
||||
}
|
||||
|
||||
public void UnstageAll()
|
||||
|
@ -1357,6 +1360,19 @@ namespace SourceGit.ViewModels
|
|||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue