From cc28453332d310dc4f6f9745fec134052a15de65 Mon Sep 17 00:00:00 2001 From: Squareys Date: Tue, 28 May 2019 12:42:04 +0200 Subject: [PATCH] Platform: Fix UTF8 text input in EmscriptenApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Squareys Co-authored-by: Vladimír Vondruš --- src/Magnum/Platform/EmscriptenApplication.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index c1c839350..72f2ed4f2 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -506,8 +506,11 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { emscripten_set_keydown_callback(keyboardListeningElement, this, false, ([](int, const EmscriptenKeyboardEvent* event, void* userData) -> Int { EmscriptenApplication& app = *static_cast(userData); - if(app.isTextInputActive() && std::strlen(event->key) == 1) { - TextInputEvent e{*event, {event->key, 1}}; + const std::size_t keyLen = std::strlen(event->key); + /* If the key name is a single letter or a start of an UTF-8 + sequence, pass it to the text input even tas well */ + if(app.isTextInputActive() && (std::strlen(event->key) == 1 || (std::strlen(event->key) >= 1 && UnsignedByte(event->key[0]) > 127))) { + TextInputEvent e{*event, {event->key, keyLen}}; app.textInputEvent(e); return e.isAccepted(); }