From 25559faaea74318a2a575e6d3483e01f5833c14a Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Fri, 19 Jul 2024 11:19:59 +0100 Subject: [PATCH] emscripten: restore key event prevent default behaviour This restores the behaviour before 92215481146f9225a458e9a09abb85a33b52d9ff where we only preventDefault the event if: - the key is recognised - the event is enabled - the event is not filtered (ignoring the KEYPRESS special case, which is unchanged) (cherry picked from commit 6e931bee01b34a9f7a51579bcaf9a95f7f9451ce) --- src/video/emscripten/SDL_emscriptenevents.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 74fc3f1568..6cfeeaed2c 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -458,7 +458,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent SDL_WindowData *window_data = (SDL_WindowData *)userData; SDL_Scancode scancode = Emscripten_MapScanCode(keyEvent->code); SDL_Keycode keycode = SDLK_UNKNOWN; - SDL_bool prevent_default = SDL_TRUE; + SDL_bool prevent_default = SDL_FALSE; SDL_bool is_nav_key = SDL_FALSE; if (scancode == SDL_SCANCODE_UNKNOWN) { @@ -511,9 +511,9 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent } if (keycode != SDLK_UNKNOWN) { - SDL_SendKeyboardKeyAndKeycode(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, keycode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED); + prevent_default = SDL_SendKeyboardKeyAndKeycode(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, keycode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED); } else { - SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED); + prevent_default = SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, 0, scancode, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED); } /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress