diff --git a/doc/changelog.dox b/doc/changelog.dox index 96c11b0d4..7a6652d70 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1194,6 +1194,12 @@ See also: work on Firefox again. The reported renderer string got changed, possibly in relation to @webgl_extension{WEBGL,debug_renderer_info} being deprecated, which broke Firefox detection in the workaround enabling code. +- @ref Platform::EmscriptenApplication was emitting only a text input event + if text input was active, not a key press event as well, making it + impossible to handle keyboard shortcuts such as copy / paste when editing + text. Now it emits both, consistently with @ref Platform::Sdl2Application + and @ref Platform::GlfwApplication, and in the same order as in those. See + [mosra/magnum#637](https://github.com/mosra/magnum/issues/637). @subsection changelog-latest-deprecated Deprecated APIs diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 8ece3d0aa..95e6c2a21 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -583,16 +583,23 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { ([](int, const EmscriptenKeyboardEvent* event, void* userData) -> Int { EmscriptenApplication& app = *static_cast(userData); const Containers::StringView key = event->key; + KeyEvent e{*event}; + app.keyPressEvent(e); + bool accepted = e.isAccepted(); + /* 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 */ + sequence, pass it to the text input event as well. Both SDL and + GLFW emit key press first and text input after, do it in the + same order here. */ if(app.isTextInputActive() && key.size() == 1 || (key.size() >= 1 && UnsignedByte(key[0]) > 127)) { - TextInputEvent e{*event, key}; - app.textInputEvent(e); - return e.isAccepted(); + TextInputEvent te{*event, key}; + app.textInputEvent(te); + accepted = accepted || te.isAccepted(); } - KeyEvent e{*event}; - app.keyPressEvent(e); - return e.isAccepted(); + + /* Accepting either the key event, the text input event, or both + should stop it from propagating further */ + return accepted; })); emscripten_set_keyup_callback(keyboardListeningElement, this, false,