ファイル

26 行
769 B
C#

namespace UndoTree;
internal static class UndoTreeSelectionLink
{
public static IReadOnlyList<object> ItemsOf(UndoTreeNodeViewModel node, UndoTreeOwners owners, Func<object, bool> isItem)
{
var items = new List<object>();
foreach (var command in node.Commands)
{
if (command.Target is { } target)
Include(items, owners.OwnersOf(target).Append(target).LastOrDefault(isItem));
foreach (var added in command.Added.Where(isItem))
Include(items, added);
}
return items;
}
static void Include(List<object> items, object? item)
{
if (item is not null && !items.Any(existing => ReferenceEquals(existing, item)))
items.Add(item);
}
}