Skip to content

Commit

Permalink
Fix WindowEvent::ReceivedCharacter on web
Browse files Browse the repository at this point in the history
The event was never sent to the application because of the unconditional
preventDefault()
call on keydown.

Fixes #1741
  • Loading branch information
tronical committed Oct 27, 2020
1 parent 66c117e commit 2a651b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- On Wayland, fix window not being resizeable when using `with_min_inner_size` in `WindowBuilder`.
- On Unix, fix cross-compiling to wasm32 without enabling X11 or Wayland.
- On Windows, fix use after free crash during window destruction.
- On Web, fix `WindowEvent::ReceivedCharacter` never being send on key input.

# 0.23.0 (2020-10-02)

Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/web/stdweb/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ impl Canvas {
F: 'static + FnMut(ScanCode, Option<VirtualKeyCode>, ModifiersState),
{
self.on_keyboard_release = Some(self.add_user_event(move |event: KeyUpEvent| {
event.prevent_default();
let event_key = &event.key();
let is_key_string = event_key.len() == 1 || !event_key.is_ascii();
if !is_key_string {
event.prevent_default();
}
handler(
event::scan_code(&event),
event::virtual_key_code(&event),
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/web/web_sys/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ impl Canvas {
self.on_keyboard_press = Some(self.common.add_user_event(
"keydown",
move |event: KeyboardEvent| {
event.prevent_default();
let event_key = &event.key();
let is_key_string = event_key.len() == 1 || !event_key.is_ascii();
if !is_key_string {
event.prevent_default();
}
handler(
event::scan_code(&event),
event::virtual_key_code(&event),
Expand Down

0 comments on commit 2a651b4

Please sign in to comment.