This commit is contained in:
neuecc 2024-08-28 03:52:42 +09:00
parent 7eef45cadb
commit 7e37cfc878
2 changed files with 20 additions and 8 deletions

View File

@ -107,7 +107,7 @@ namespace ObservableCollections
} }
} }
ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset)); ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset, true));
} }
} }
@ -117,7 +117,7 @@ namespace ObservableCollections
{ {
this.filter = SynchronizedViewFilter<T>.Null; this.filter = SynchronizedViewFilter<T>.Null;
this.filteredCount = list.Count; this.filteredCount = list.Count;
ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset)); ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset, true));
} }
} }
@ -208,15 +208,14 @@ namespace ObservableCollections
{ {
var i = e.NewStartingIndex; var i = e.NewStartingIndex;
//new CloneCollection<(T, TView)>();
using var array = new ResizableArray<(T, TView)>(e.NewItems.Length); using var array = new ResizableArray<(T, TView)>(e.NewItems.Length);
foreach (var item in e.NewItems) foreach (var item in e.NewItems)
{ {
var v = (item, selector(item)); array.Add((item, selector(item)));
list.Add(v);
this.InvokeOnAdd(ref filteredCount, ViewChanged, v, i++);
} }
list.AddRange(array.Span);
this.InvokeOnAdd(ref filteredCount, ViewChanged, v, i++);
} }
} }
// Insert // Insert

View File

@ -52,7 +52,20 @@ namespace ObservableCollections
filteredCount++; filteredCount++;
if (ev != null) if (ev != null)
{ {
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Add, newValue: value, newView: view, newViewIndex: index)); ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Add, true, newItem: (value, view), newStartingIndex: index));
}
}
}
internal static void InvokeOnAddRange<T, TView>(this ISynchronizedView<T, TView> collection, ref int filteredCount, NotifyViewChangedEventHandler<T, TView>? ev, ReadOnlySpan<T> values, ReadOnlySpan<TView> views, int index)
{
var isMatch = collection.Filter.IsMatch(value);
if (isMatch)
{
filteredCount++;
if (ev != null)
{
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Add, false, newValues: values, newViews: views, newStartingIndex: index));
} }
} }
} }