Browse Source

Merge branch 'master' into issues/1998

pull/2002/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
f1cf94c6a6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/Avalonia.Base/Collections/AvaloniaListExtensions.cs
  2. 29
      tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs

7
src/Avalonia.Base/Collections/AvaloniaListExtensions.cs

@ -104,7 +104,12 @@ namespace Avalonia.Collections
case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Replace:
Remove(e.OldStartingIndex, e.OldItems); Remove(e.OldStartingIndex, e.OldItems);
Add(e.NewStartingIndex, e.NewItems); int newIndex = e.NewStartingIndex;
if(newIndex > e.OldStartingIndex)
{
newIndex -= e.OldItems.Count;
}
Add(newIndex, e.NewItems);
break; break;
case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Remove:

29
tests/Avalonia.Base.UnitTests/Collections/AvaloniaListExtenionsTests.cs

@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using Avalonia.Collections; using Avalonia.Collections;
using Xunit; using Xunit;
@ -82,13 +81,31 @@ namespace Avalonia.Base.UnitTests.Collections
Assert.Equal(source, result); Assert.Equal(source, result);
} }
[Fact] [Theory]
public void CreateDerivedList_Handles_MoveRange() [InlineData(0, 2, 3)]
[InlineData(0, 2, 4)]
[InlineData(0, 2, 5)]
[InlineData(0, 4, 4)]
[InlineData(1, 2, 0)]
[InlineData(1, 2, 4)]
[InlineData(1, 2, 5)]
[InlineData(1, 4, 0)]
[InlineData(2, 2, 0)]
[InlineData(2, 2, 1)]
[InlineData(2, 2, 3)]
[InlineData(2, 2, 4)]
[InlineData(2, 2, 5)]
[InlineData(4, 2, 0)]
[InlineData(4, 2, 1)]
[InlineData(4, 2, 3)]
[InlineData(5, 1, 0)]
[InlineData(5, 1, 3)]
public void CreateDerivedList_Handles_MoveRange(int oldIndex, int count, int newIndex)
{ {
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3, 4, 5 });
var target = source.CreateDerivedList(x => new Wrapper(x)); var target = source.CreateDerivedList(x => new Wrapper(x));
source.MoveRange(1, 2, 0); source.MoveRange(oldIndex, count, newIndex);
var result = target.Select(x => x.Value).ToList(); var result = target.Select(x => x.Value).ToList();

Loading…
Cancel
Save