desmosinc / mathquill

Magic textboxes where you can type math as easily as writing!
mathquill.com
137 stars 42 forks source link

Work around Linux and Chrome Unicode entry bug #251

Closed sclower closed 2 years ago

sclower commented 2 years ago

In Linux and Chrome or Chrome OS, users may issue the Ctrl-Shift-U command to input a Unicode character. Unfortunately, when the system is in this state, Chrome sends a keydown of "Ctrl-Shift-Unidentified" in Linux, "Ctrl-Shift-U" on Windows/Mac, or "Ctrl-Shift-Process" in the latest Chrome OS. Equally vexing is that the keyup correctly comes back as Ctrl-Shift-U. Furthermore, an input event with the value "u" is still processed in Linux and Chrome OS due to the down/up mismatch. The end result is that a spurious "u" is sent followed by the intended character.

Due to how this feature works, it's vital to completely ignore Ctrl-Shift-U no matter how the input event appears to Mathquill as clearing the textarea by mistake breaks the expected input flow.

I have verified this works in Ubuntu 22.04 and Chrome OS 105 (updated October 2022). The user who reported the symptom also confirms this change fixes the issue inside the Desmos calculators.

jwmerrill commented 2 years ago

I'm curious, did you end up investigating event.isComposing as part of this work? https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/isComposing

It seems like it could be relevant to this situation.

jwmerrill commented 2 years ago

Would you mind rebasing out the commits that add and remove debugging code? I think there's extra value in keeping the commit history clean in this repo since we need to coordinate with upstream about moving changes back and forth.

sclower commented 2 years ago

I did investigate the Keyboard.isComposing property, and results were mixed. In Ubuntu, it was always set to false. In Chrome OS, it would remain true for the duration of the input sequence, e.g. from the user pressing Ctrl-Shift-U, entering the symbol, and pressing Space or Enter to terminate entry. At this point it doesn't appear to be implemented widely enough to rely on.

I will squash/rebase.