From e432559a5e1c9157a838ce55ea16857257c070b9 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 6 Jun 2024 09:53:26 +0800 Subject: [PATCH] enhance: only change the selected changes if it is necessary --- src/Views/ChangeCollectionView.axaml.cs | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Views/ChangeCollectionView.axaml.cs b/src/Views/ChangeCollectionView.axaml.cs index 07623696..5d0694c0 100644 --- a/src/Views/ChangeCollectionView.axaml.cs +++ b/src/Views/ChangeCollectionView.axaml.cs @@ -116,9 +116,7 @@ namespace SourceGit.Views foreach (var c in model.SelectedItems) CollectChangesInNode(selected, c); - _isSelecting = true; - SetCurrentValue(SelectedChangesProperty, selected); - _isSelecting = false; + TrySetSelected(selected); } }; @@ -144,9 +142,7 @@ namespace SourceGit.Views foreach (var c in model.SelectedItems) selected.Add(c); - _isSelecting = true; - SetCurrentValue(SelectedChangesProperty, selected); - _isSelecting = false; + TrySetSelected(selected); } }; @@ -172,9 +168,7 @@ namespace SourceGit.Views foreach (var c in model.SelectedItems) selected.Add(c); - _isSelecting = true; - SetCurrentValue(SelectedChangesProperty, selected); - _isSelecting = false; + TrySetSelected(selected); } }; @@ -269,6 +263,34 @@ 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; + } + + _isSelecting = true; + SetCurrentValue(SelectedChangesProperty, changes); + _isSelecting = false; + } + private bool _isSelecting = false; } }