diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 9f447394..4a5c7c4e 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -137,7 +137,8 @@ namespace SourceGit.ViewModels } else { - SelectedStaged = []; + if (_selectedStaged != null && _selectedStaged.Count > 0) + SelectedStaged = []; if (value.Count == 1) SetDetail(value[0]); @@ -162,7 +163,8 @@ namespace SourceGit.ViewModels } else { - SelectedUnstaged = []; + if (_selectedUnstaged != null && _selectedUnstaged.Count > 0) + SelectedUnstaged = []; if (value.Count == 1) SetDetail(value[0]); diff --git a/src/Views/ChangeCollectionView.axaml.cs b/src/Views/ChangeCollectionView.axaml.cs index e62defef..5f48a03e 100644 --- a/src/Views/ChangeCollectionView.axaml.cs +++ b/src/Views/ChangeCollectionView.axaml.cs @@ -174,8 +174,9 @@ namespace SourceGit.Views return; _disableSelectionChangingEvent = true; + var selected = new List(); - if (sender is ListBox { SelectedItems: not null } list) + if (sender is ListBox list) { foreach (var item in list.SelectedItems) { @@ -186,7 +187,27 @@ namespace SourceGit.Views } } - TrySetSelected(selected); + var old = SelectedChanges ?? []; + if (old.Count != selected.Count) + { + SetCurrentValue(SelectedChangesProperty, selected); + } + else + { + bool allEquals = true; + foreach (var c in old) + { + if (!selected.Contains(c)) + { + allEquals = false; + break; + } + } + + if (!allEquals) + SetCurrentValue(SelectedChangesProperty, selected); + } + _disableSelectionChangingEvent = false; } @@ -330,33 +351,6 @@ namespace SourceGit.Views } } - private void TrySetSelected(List changes) - { - var old = SelectedChanges; - if (old == null && changes.Count == 0) - return; - - if (old != null && old.Count == changes.Count) - { - bool allEquals = true; - foreach (var c in old) - { - if (!changes.Contains(c)) - { - allEquals = false; - break; - } - } - - if (allEquals) - return; - } - - _disableSelectionChangingEvent = true; - SetCurrentValue(SelectedChangesProperty, changes); - _disableSelectionChangingEvent = false; - } - private bool _disableSelectionChangingEvent = false; } }