-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce usage of legacy event.keyCode
. NFC
#22881
base: main
Are you sure you want to change the base?
Conversation
I noticed this could be improved while reviewing #22879. Whichever lands first will have to deal with a conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm if relevant interactive tests pass. By my reading of the MDN docs this looks valid.
src/library_sdl.js
Outdated
@@ -553,7 +553,7 @@ var LibrarySDL = { | |||
receiveEvent(event) { | |||
function unpressAllPressedKeys() { | |||
// Un-press all pressed keys: TODO | |||
for (var keyCode of SDL.keyboardMap) { | |||
for (var keyCode of Object.values(SDL.keyboardMap)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the crash fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I see this crash when running the interactive tests.
@@ -313,7 +313,7 @@ if (!ENVIRONMENT_IS_NODE) { | |||
// Only prevent default on backspace/tab because we don't want unexpected navigation. | |||
// Do not prevent default on the rest as we need the keypress event. | |||
function shouldPreventDefault(event) { | |||
if (event.type === 'keydown' && event.keyCode !== 8 /* backspace */ && event.keyCode !== 9 /* tab */) { | |||
if (event.type === 'keydown' && event.key != 'Backspace' && event.key != 'Tab') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW the logic here seems to be the inverse of what the comment says. Shouldn't all the clauses above be ===
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right to me? Comment above says "prevent default on backspace/tab", the if checks "not backspace, not tab" and returns false if so. So it returns true - prevents default - on backspace/tab as described.
I split out the crash fix: #22884 |
This change replaced the usage of the legacy `keyCode` attribute with the preferred `key` attribute, which also has the advantage of removing some hardcoded constant numbers. In order to test this change I fixed the `test_glfw_get_key_stuck` test and added `test_sdl_key_test` to the interactive tests. In doing so I noticed and fixed a crash bug that was introduced in emscripten-core#22874.
This change replaced the usage of the legacy
keyCode
attribute with the preferredkey
attribute, which also has the advantage of removing some hardcoded constant numbers.In order to test this change I fixed the
test_glfw_get_key_stuck
test and addedtest_sdl_key_test
to the interactive tests.In doing so I noticed and fixed a crash bug that was introduced in #22874.