Browse Source

Merge branch 'master' into textInputMethodClientRework

pull/11848/head
Dan Walmsley 3 years ago
committed by GitHub
parent
commit
cc4361f3ed
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Controls/ListBox.cs
  2. 45
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

2
src/Avalonia.Controls/ListBox.cs

@ -148,7 +148,7 @@ namespace Avalonia.Controls
}
else if (e.Key == Key.Space || e.Key == Key.Enter)
{
e.Handled |= UpdateSelectionFromEventSource(
UpdateSelectionFromEventSource(
e.Source,
true,
e.KeyModifiers.HasFlag(KeyModifiers.Shift),

45
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -1247,6 +1247,51 @@ namespace Avalonia.Controls.UnitTests
data.GetRealizedItems());
}
[Fact]
public void Should_Not_Handle_Space_When_TextBox_Inside_ListBoxItem()
{
using (UnitTestApplication.Start(TestServices.RealFocus))
{
var target = new TextBox
{
Focusable = true
};
var listbox = new ListBox()
{
Template = ListBoxTemplate(),
Items =
{
new ListBoxItem()
{
Template = ListBoxItemTemplate(),
Content = target,
}
}
};
var nKeyDown = 0;
var root = new TestRoot()
{
Width = 1000,
Height = 1000,
Child = listbox,
};
root.KeyDown += (s, e) => nKeyDown++;
listbox.ApplyTemplate();
root.LayoutManager.ExecuteInitialLayoutPass();
target.Focus();
RaiseKeyEvent(target, Key.Space, KeyModifiers.None);
Assert.Equal(1, nKeyDown);
}
}
private static void RaiseKeyEvent(Control target, Key key, KeyModifiers inputModifiers = 0)
{
target.RaiseEvent(new KeyEventArgs

Loading…
Cancel
Save