Browse Source

Platform: emit both the text input and key press event in EmscriptenApp.

This is what both SDL and GLFW do, so it makes sense to be consistent.
Without it it's also impossible to handle keyboard shortcuts such as
Ctrl-C when editing text, which is rather silly.
pull/638/head
Vladimír Vondruš 2 years ago
parent
commit
536d4e75fe
  1. 6
      doc/changelog.dox
  2. 21
      src/Magnum/Platform/EmscriptenApplication.cpp

6
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

21
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<EmscriptenApplication*>(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,

Loading…
Cancel
Save