Closed MauriceKayser closed 1 year ago
By logging the key (here) in the interpreter, you can see that the webview outputs unicode escape characters instead of the key pressed: Ctrl-S outputs key: "\u0013"
, Ctrl-A outputs key: "\u0001"
. Which fails to deserialize. (Note these unicode characters are control characters, not the codes for s and a)
Here is the same example in JS: https://jsfiddle.net/6uxko9a2/
For reference of the Ctrl+@
- Ctrl+_
keys: https://www.physics.udel.edu/~watson/scen103/ascii.html
I pressed Ctrl+A
in your jsfiddle in a few different browsers: Brave (Chromium), Edge (Chromium) and Firefox, and recorded the relevant values of the KeyboardEvent
:
OS | Browser | Chromium | charCode | code | ctrlKey | key | keyCode | which |
---|---|---|---|---|---|---|---|---|
Linux | Brave | Yes | 1 | "KeyA" | true | "a" | 1 | 1 |
Linux | Edge | Yes | 1 | "KeyA" | true | "a" | 1 | 1 |
Windows | Brave | Yes | 1 | "KeyA" | true | "\u0001" | 1 | 1 |
Windows | Edge | Yes | 1 | "KeyA" | true | "\u0001" | 1 | 1 |
Linux & Windows | Firefox | No | - | - | - | - | - | - |
Seems like the issue is related to Windows + Chromium. Firefox does not generate any KeyboardEvent
for the Ctrl+
key presses. charCode
, keyCode
and which
all seem to be the same (e.g. when trying with Ctrl+B
they all are 2
). I could only get Chromium to output the control codes for Ctrl+A
- Ctrl+Z
on my German keyboard, not any of the Ctrl+@
, Ctrl+[
etc.
Which option would you prefer, adding the Ctrl+[
to Ctrl+_
(or only Ctrl+A
- Ctrl+Z
) keys to the keyboard-types crate, or modifing dioxus, for example by patching key
from "\u0001"
to "a"
?
If we override this behavior it should probably be at the Dioxus level, not in keyboard-types. Decoding the Unicode values for Escape and Backspace as not escape and backspace should probably not be part of that crate.
Reading the mdn docs on KeyboardEvent.key, the escape and backspace key codes are a valid value for key. If they are it feels wrong to decode the Unicode version of escape as something other than escape or backspace.
React's solution seems to be to just ignore the event in all cases: https://playcode.io/1170117
We should definitely not panic when we fail to decode the character. We can use the Unknown variant of the enum instead.
This issue also appears to be specific to onkeypress, onkeydown works fine in the js playground example
Problem
Stack backtrace:
``` 0: std::panicking::begin_panic_handler at /rustc/3020239de947ec52677e9b4e853a6a9fc073d1f9/library\std\src\panicking.rs:575 1: core::panicking::panic_fmt at /rustc/3020239de947ec52677e9b4e853a6a9fc073d1f9/library\core\src\panicking.rs:64 2: core::result::unwrap_failed at /rustc/3020239de947ec52677e9b4e853a6a9fc073d1f9/library\core\src\result.rs:1790 3: enum2$Steps To Reproduce
Ctrl
, pressA
.Environment:
master
nightly
Windows 11
desktop
Questionnaire