Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

TextBox is processing already handled events on Linux

Open danipen opened this issue 3 years ago • 1 comments

Describe the bug Under Linux OS, when explicitly handing a keydown event, in some cases the TextBox still processes the TextInput event.

Note that the repro example is handling the keydown event as handled, however the TextBox is still processing that input:

protected override void OnKeyDown(KeyEventArgs e)
{
    base.OnKeyDown(e);

    if (e.KeyModifiers.HasFlag(KeyModifiers.Control))
    {
        mLogTextBox.Text += "Pressed Ctrl+" + e.Key + Environment.NewLine;
        e.Handled = true;
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Clone the following minimal example: https://github.com/danipen/LinuxHandleKeyDown
  2. Run the example.
  3. Hit Ctrl + 1 (or any other key combination that reproduces the issue).
  4. See that the textbox writes a 1 in the text and shouldn't.

Expected behavior

  • macOS and Windows OS are working as expected (when the KeyDown event is marked as e.Handled = true, the TextBox doesn't process that TextInput. See the following video. https://user-images.githubusercontent.com/501613/196429137-dcc6ebb2-dcb5-414c-8f4b-836865ad23be.mov

  • Only Linux OS reproduces the wrong behavior. See the following video. https://user-images.githubusercontent.com/501613/196429240-a2fee008-b8c0-47e0-bdf2-0d78b0f08514.mov

Screenshots Screenshot 2022-10-18 at 14 11 47

Desktop (please complete the following information):

  • OS: Linux Ubuntu 20.04.
  • Version 11.0.0-preview2

Additional context Note that there are several key combinations that reproduce the issue: Ctrl + + Ctrl + - Ctrl + 1 Ctrl + 9 Ctrl + / Ctrl + * Ctrl + < etc...

Note also that other similar key combinations doesn't repro the issue, such as Ctrl + 5

danipen avatar Oct 18 '22 12:10 danipen

I encountered same problem while developed #8539 The problem in x11 is there: https://github.com/AvaloniaUI/Avalonia/blob/9a9339527791b84dac478e1142b033b9ba42e84e/src/Avalonia.X11/X11Window.Ime.cs#L95-L114

https://github.com/AvaloniaUI/Avalonia/blob/9a9339527791b84dac478e1142b033b9ba42e84e/src/Avalonia.X11/X11Window.Ime.cs#L159-L169

https://github.com/AvaloniaUI/Avalonia/blob/ae7298bf50df80f463ab9260535b39434fc5ebcc/src/Avalonia.X11/X11Window.Ime.cs#L116-L123

https://github.com/AvaloniaUI/Avalonia/blob/ae7298bf50df80f463ab9260535b39434fc5ebcc/src/Avalonia.X11/X11Window.cs#L749-L757

it is not possible to know if the event was handled by sendinput before call TriggerClassicTextInputEvent

workgroupengineering avatar Oct 18 '22 14:10 workgroupengineering