-
Notifications
You must be signed in to change notification settings - Fork 940
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
Fix WindowEvent::ReceivedCharacter on web #1747
Conversation
Looks good! Before we merge, we have to address the compile error on stdweb. Importing |
Thank you! That did the trick :) |
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.
See inline review. Also, I think the code deserves at least a short comment to describe what it does and why it is needed.
let event_key = &event.key(); | ||
let is_key_string = event_key.len() == 1 || !event_key.is_ascii(); | ||
if !is_key_string { | ||
event.prevent_default(); | ||
} |
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.
Shouldn't this be put inside on_keyboard_press
instead of on_keyboard_release
?
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.
Ouch, yes, of course. Thanks for spotting!
Sorry, this doesn't block normal shortcut keys (e.g. Ctrl+R), but it does block function keys (e.g. F5). It does appear that we still need to check for modifiers. This should work, but I'm not entirely sure if it does what people usually expects AltGr to do: let is_shortcut_modifiers = (event.ctrl_key() || event.alt_key()) && !event.get_modifier_state("AltGr");
if !is_key_string || is_shortcut_modifiers {
event.prevent_default();
} Also, I believe you need to add |
Done. Also added the missing comment, you're totally right that the handling needs it.
I'm not sure I understand, can you elaborate? |
The remaining CI failure looks like an unrelated network problem to me. |
Open https://codepen.io/alvinhochun/pen/yLJpwGX, focus on the canvas and try pressing Space. You will find that the page gets scrolled down. Uncomment |
The event was never sent to the application because of the unconditional preventDefault() call on keydown. Fixes rust-windowing#1741
After reaching keypress, we should prevent further propagation. Relates to rust-windowing#1741
Got it, thanks! Added this in a follow-up commit on top (and fixed changelog grammar in initial commit). |
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 good to me!
The event was never sent to the application because of the unconditional
preventDefault()
call on keydown.
Fixes #1741
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to users