Skip to content

Commit e432559

Browse files
committed
enhance: only change the selected changes if it is necessary
1 parent 2c0a58a commit e432559

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/Views/ChangeCollectionView.axaml.cs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ private void UpdateSource()
116116
foreach (var c in model.SelectedItems)
117117
CollectChangesInNode(selected, c);
118118

119-
_isSelecting = true;
120-
SetCurrentValue(SelectedChangesProperty, selected);
121-
_isSelecting = false;
119+
TrySetSelected(selected);
122120
}
123121
};
124122

@@ -144,9 +142,7 @@ private void UpdateSource()
144142
foreach (var c in model.SelectedItems)
145143
selected.Add(c);
146144

147-
_isSelecting = true;
148-
SetCurrentValue(SelectedChangesProperty, selected);
149-
_isSelecting = false;
145+
TrySetSelected(selected);
150146
}
151147
};
152148

@@ -172,9 +168,7 @@ private void UpdateSource()
172168
foreach (var c in model.SelectedItems)
173169
selected.Add(c);
174170

175-
_isSelecting = true;
176-
SetCurrentValue(SelectedChangesProperty, selected);
177-
_isSelecting = false;
171+
TrySetSelected(selected);
178172
}
179173
};
180174

@@ -269,6 +263,34 @@ private void CollectSelectedNodeByChange(List<Models.FileTreeNode> outs, Models.
269263
}
270264
}
271265

266+
private void TrySetSelected(List<Models.Change> changes)
267+
{
268+
var old = SelectedChanges;
269+
270+
if (old == null && changes.Count == 0)
271+
return;
272+
273+
if (old != null && old.Count == changes.Count)
274+
{
275+
bool allEquals = true;
276+
foreach (var c in old)
277+
{
278+
if (!changes.Contains(c))
279+
{
280+
allEquals = false;
281+
break;
282+
}
283+
}
284+
285+
if (allEquals)
286+
return;
287+
}
288+
289+
_isSelecting = true;
290+
SetCurrentValue(SelectedChangesProperty, changes);
291+
_isSelecting = false;
292+
}
293+
272294
private bool _isSelecting = false;
273295
}
274296
}

0 commit comments

Comments
 (0)