fix: keep selected commit after _commits var reassigned

This commit is contained in:
Gadfly 2024-04-30 21:22:48 +08:00
parent 1fe050ed0b
commit 2e60c98eee
No known key found for this signature in database
GPG key ID: 9128145F93CFC69C

View file

@ -34,8 +34,19 @@ namespace SourceGit.ViewModels
get => _commits;
set
{
var oldAutoSelectedCommitSHA = AutoSelectedCommit?.SHA;
if (SetProperty(ref _commits, value))
{
Models.Commit newSelectedCommit = null;
if (value.Count > 0 && oldAutoSelectedCommitSHA != null)
{
newSelectedCommit = value.Find(x => x.SHA == oldAutoSelectedCommitSHA);
}
if (newSelectedCommit != AutoSelectedCommit)
{
AutoSelectedCommit = newSelectedCommit;
}
Graph = null;
Task.Run(() =>
{