|
|
|
@ -1762,6 +1762,18 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Empty(target.SelectedIndices); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Assigning_Source_With_Less_Items_Than_Previous_Clears_Selection() |
|
|
|
{ |
|
|
|
var data = new[] { "foo", "bar", "baz", "boo", "hoo" }; |
|
|
|
var smallerData = new[] { "foo", "bar", "baz" }; |
|
|
|
var target = new SelectionModel { RetainSelectionOnReset = true }; |
|
|
|
target.Source = data; |
|
|
|
target.SelectedIndex = new IndexPath(4); |
|
|
|
target.Source = smallerData; |
|
|
|
Assert.Empty(target.SelectedIndices); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Assigning_Source_With_Less_Items_Than_Selection_Trims_Selection() |
|
|
|
{ |
|
|
|
@ -1772,6 +1784,18 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Empty(target.SelectedIndices); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Assigning_Source_With_Less_Items_Than_Multiple_Selection_Trims_Selection() |
|
|
|
{ |
|
|
|
var data = new[] { "foo", "bar", "baz" }; |
|
|
|
var target = new SelectionModel { RetainSelectionOnReset = true }; |
|
|
|
target.Select(4); |
|
|
|
target.Select(2); |
|
|
|
target.Source = data; |
|
|
|
Assert.Equal(1, target.SelectedIndices.Count); |
|
|
|
Assert.Equal(new IndexPath(2), target.SelectedIndices.First()); |
|
|
|
} |
|
|
|
|
|
|
|
private int GetSubscriberCount(AvaloniaList<object> list) |
|
|
|
{ |
|
|
|
return ((INotifyCollectionChangedDebug)list).GetCollectionChangedSubscribers()?.Length ?? 0; |
|
|
|
|