mosra/magnum

EmscriptenApplication keyboard handler doesn't send key event corresponding to text input events

CaseyCarlin opened this issue · 2 comments

The keyboard handler in the emscripten backend has this section:

/* If the key name is a single letter or a start of an UTF-8
   sequence, pass it to the text input event as well */
if(app.isTextInputActive() && key.size() == 1 || (key.size() >= 1 && UnsignedByte(key[0]) > 127)) {
    TextInputEvent e{*event, key};
    app.textInputEvent(e);
    return e.isAccepted();
}

The comment says "pass it to the text input event as well" but this conditional returns instead.

Because of this, when passing events to the Magnum ImGui integration, ImGui will only ever get a KeyDown event or a TextInput event; never both. Furthermore, if ImGui does not get a key event to correspond with a text event, keyboard shortcuts never fire inside Input widgets.

Based on the code comment above, it seems like return e.isAccepted(); should be removed, and indeed in my local branch this does re-enable keyboard shortcuts in input widgets with no apparent ill effects.

Oh, that's quite bad actually, I wonder how nobody came across that until now.

I cross-checked with the SDL2 and GLFW application implementations and they emit both events, so it makes sense to do that here as well. Did some more adjustments to make the accept status propagate from both the press and key events (because otherwise they'd get propagated further to the page / browser), and commited the fix as 536d4e7.

Thank you!

Thank you as well!