Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selection of multiple consecutive blocks in SelectingItemsControl. #16907

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,10 @@ protected void UpdateSelection(
else if (range)
{
using var operation = Selection.BatchUpdate();
Selection.Clear();
if (!toggleModifier)
{
Selection.Clear();
}
Selection.SelectRange(Selection.AnchorIndex, index);
}
else if (!fromFocus && toggle)
Expand Down
30 changes: 30 additions & 0 deletions tests/Avalonia.Controls.UnitTests/ListBoxTests_Multiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ public void Ctrl_Selecting_Non_SelectedItem_With_Multiple_Selection_Active_Leave
}
}

[Fact]
public void ToggleModifier_And_Range_Should_Select_Second_Range()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var target = new ListBox
{
Template = new FuncControlTemplate(CreateListBoxTemplate),
ItemsSource = new[] { "Foo", "Bar", "Baz", "Gap", "Boo", "Far", "Faz" },
SelectionMode = SelectionMode.Multiple,
Width = 100,
Height = 100,
};

var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass();

AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
// Select first range
_helper.Click(target.Presenter.Panel.Children[0]);
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);

// Select second range
_helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
_helper.Click(target.Presenter.Panel.Children[6], modifiers: KeyModifiers.Control | KeyModifiers.Shift);

Assert.Equal(new[] { "Foo", "Bar", "Baz", "Boo", "Far", "Faz" }, target.SelectedItems);
}
}

[Fact]
public void Should_Ctrl_Select_Correct_Item_When_Duplicate_Items_Are_Present()
{
Expand Down
Loading