Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#9699 from AvaloniaUI/fixes/7974-selecti…
Browse files Browse the repository at this point in the history
…onmodel-eventargs-indexer

Fix SelectionModelSelectionChangedEventArgs.SelectedItems indexer.
  • Loading branch information
maxkatz6 authored and grokys committed Feb 16, 2023
1 parent f3acb6e commit 730e08d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Selection/SelectedItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public SelectedItems(IReadOnlyList<IndexRange> ranges, ItemsSourceView<T>? items
{
return _owner.SelectedItem;
}
else if (Items is object)
else if (Items is not null && Ranges is not null)
{
return Items[index];
return Items[IndexRange.GetAt(Ranges, index)];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Selection;
using Avalonia.Controls.Utils;
Expand Down Expand Up @@ -1144,6 +1145,24 @@ public void Handles_Selection_Made_In_CollectionChanged()
Assert.Equal(new[] { "foo" }, target.SelectedItems);
Assert.Equal(0, target.AnchorIndex);
}

[Fact]
public void SelectedItems_Indexer_Is_Correct()
{
// Issue #7974
var target = CreateTarget();
var raised = 0;

target.SelectionChanged += (s, e) =>
{
Assert.Equal("bar", e.SelectedItems.First());
Assert.Equal("bar", e.SelectedItems[0]);
++raised;
};

target.Select(1);
Assert.Equal(1, raised);
}
}

public class BatchUpdate
Expand Down

0 comments on commit 730e08d

Please sign in to comment.