diff --git a/src/Android/Avalonia.Android/Platform/Input/AvaloniaInputConnection.cs b/src/Android/Avalonia.Android/Platform/Input/AvaloniaInputConnection.cs index a93803db09..b79043db32 100644 --- a/src/Android/Avalonia.Android/Platform/Input/AvaloniaInputConnection.cs +++ b/src/Android/Avalonia.Android/Platform/Input/AvaloniaInputConnection.cs @@ -311,7 +311,7 @@ namespace Avalonia.Android.Platform.Input public bool SendKeyEvent(KeyEvent? e) { - _inputMethod.View.DispatchKeyEvent(e); + QueueCommand(new KeyEventCommand(e)); return true; } diff --git a/src/Android/Avalonia.Android/Platform/Input/EditCommand.cs b/src/Android/Avalonia.Android/Platform/Input/EditCommand.cs index c110807dd9..33d4449725 100644 --- a/src/Android/Avalonia.Android/Platform/Input/EditCommand.cs +++ b/src/Android/Avalonia.Android/Platform/Input/EditCommand.cs @@ -1,4 +1,5 @@ using System; +using Android.Views; using Avalonia.Input.TextInput; namespace Avalonia.Android.Platform.Input @@ -177,4 +178,19 @@ namespace Avalonia.Android.Platform.Input buffer.Composition = default; } } + + internal class KeyEventCommand : EditCommand + { + private readonly KeyEvent? _keyEvent; + + public KeyEventCommand(KeyEvent? keyEvent) + { + _keyEvent = keyEvent; + } + + public override void Apply(TextEditBuffer buffer) + { + buffer.DispatchKeyEvent(_keyEvent); + } + } } diff --git a/src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs b/src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs index 9cbefab24a..3c25772d72 100644 --- a/src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs +++ b/src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs @@ -131,5 +131,11 @@ namespace Avalonia.Android.Platform.Input Composition = null; } } + + + internal void DispatchKeyEvent(KeyEvent? keyEvent) + { + _textInputMethod?.View.DispatchKeyEvent(keyEvent); + } } }