Browse Source

Merge branch 'feature/selectionmodel-reset-handling' into feature/selectionmodel-autoselect

pull/3509/head
Steven Kirk 6 years ago
parent
commit
565de5b2e7
  1. 2
      src/Avalonia.Controls/SelectionModel.cs
  2. 27
      tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs

2
src/Avalonia.Controls/SelectionModel.cs

@ -533,6 +533,8 @@ namespace Avalonia.Controls
ApplyAutoSelect(); ApplyAutoSelect();
} }
public IDisposable Update() => new Operation(this);
protected void OnPropertyChanged(string propertyName) protected void OnPropertyChanged(string propertyName)
{ {
RaisePropertyChanged(propertyName); RaisePropertyChanged(propertyName);

27
tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs

@ -1639,6 +1639,33 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(3, raised); Assert.Equal(3, raised);
Assert.Equal(new[] { new IndexPath(2) }, target.SelectedIndices); Assert.Equal(new[] { new IndexPath(2) }, target.SelectedIndices);
} }
[Fact]
public void Can_Batch_Update()
{
var target = new SelectionModel();
var raised = 0;
target.Source = Enumerable.Range(0, 10).ToList();
target.Select(1);
target.SelectionChanged += (s, e) =>
{
Assert.Equal(new[] { new IndexPath(1) }, e.DeselectedIndices);
Assert.Equal(new object[] { 1 }, e.DeselectedItems);
Assert.Equal(new[] { new IndexPath(4) }, e.SelectedIndices);
Assert.Equal(new object[] { 4 }, e.SelectedItems);
++raised;
};
using (target.Update())
{
target.Deselect(1);
target.Select(4);
}
Assert.Equal(1, raised);
}
[Fact] [Fact]
public void AutoSelect_Selects_When_Enabled() public void AutoSelect_Selects_When_Enabled()

Loading…
Cancel
Save