Browse Source

Merge pull request #3096 from AvaloniaUI/fixes/3094-focusable-hang

Fix hang in ItemsControl.MoveSelection
release/0.9.0-preview2
danwalmsley 7 years ago
committed by Dan Walmsley
parent
commit
86a1faff9a
  1. 8
      src/Avalonia.Controls/ItemsControl.cs
  2. 28
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

8
src/Avalonia.Controls/ItemsControl.cs

@ -489,18 +489,20 @@ namespace Avalonia.Controls
bool wrap) bool wrap)
{ {
IInputElement result; IInputElement result;
var c = from;
do do
{ {
result = container.GetControl(direction, from, wrap); result = container.GetControl(direction, c, wrap);
from = from ?? result;
if (result?.Focusable == true) if (result?.Focusable == true)
{ {
return result; return result;
} }
from = result; c = result;
} while (from != null); } while (c != null && c != from);
return null; return null;
} }

28
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -1000,6 +1000,26 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(new[] { "Bar" }, selectedItems); Assert.Equal(new[] { "Bar" }, selectedItems);
} }
[Fact]
public void MoveSelection_Wrap_Does_Not_Hang_With_No_Focusable_Controls()
{
// Issue #3094.
var target = new TestSelector
{
Template = Template(),
Items = new[]
{
new ListBoxItem { Focusable = false },
new ListBoxItem { Focusable = false },
},
SelectedIndex = 0,
};
target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));
target.MoveSelection(NavigationDirection.Next, true);
}
private FuncControlTemplate Template() private FuncControlTemplate Template()
{ {
return new FuncControlTemplate<SelectingItemsControl>((control, scope) => return new FuncControlTemplate<SelectingItemsControl>((control, scope) =>
@ -1044,5 +1064,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" }; public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" };
public string Selected { get; set; } = "b"; public string Selected { get; set; } = "b";
} }
private class TestSelector : SelectingItemsControl
{
public new bool MoveSelection(NavigationDirection direction, bool wrap)
{
return base.MoveSelection(direction, wrap);
}
}
} }
} }

Loading…
Cancel
Save