enhance: improve selection changed event handler performance

This commit is contained in:
leo 2024-07-06 17:29:24 +08:00
parent 3197b4bfe8
commit 36b8472d02
No known key found for this signature in database
2 changed files with 11 additions and 8 deletions

View file

@ -16,6 +16,7 @@ namespace SourceGit.ViewModels
public object Backend { get; private set; } = null;
public int Depth { get; set; } = 0;
public bool IsFiltered { get; set; } = false;
public bool IsSelected { get; set; } = false;
public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>();
public bool IsExpanded

View file

@ -154,21 +154,24 @@ namespace SourceGit.Views
if (selected == null || selected.Count == 0)
return;
var set = new HashSet<ViewModels.BranchTreeNode>();
foreach (var item in selected)
foreach (var item in e.AddedItems)
{
if (item is ViewModels.BranchTreeNode node)
set.Add(node);
node.IsSelected = true;
}
foreach (var item in e.RemovedItems)
{
if (item is ViewModels.BranchTreeNode node)
node.IsSelected = false;
}
var prev = null as ViewModels.BranchTreeNode;
var isPrevSelected = false;
foreach (var row in Rows)
{
var isSelected = set.Contains(row);
if (isSelected)
if (row.IsSelected)
{
if (isPrevSelected)
if (prev is { IsSelected: true })
{
var prevTop = prev.CornerRadius.TopLeft;
prev.CornerRadius = new CornerRadius(prevTop, 0);
@ -180,7 +183,6 @@ namespace SourceGit.Views
}
}
isPrevSelected = isSelected;
prev = row;
}