Closed Bug 1840519 Opened 1 year ago Closed 11 months ago

`TextEditor` and `HTMLEditor` should handle `keypress` events with `.key` value instead of `.charCode` value (in early beta builds and nightly builds)

Categories

(Core :: DOM: Editor, defect, P2)

defect

Tracking

()

RESOLVED FIXED
118 Branch
Tracking Status
firefox118 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Currently, both TextEditor and HTMLEditor handles keypress events with their .charCode value. This may cause dispatching beforeinput and input events with one surrogate value data attribute.

Therefore, they should handle it once per a surrogate pair, which is stored in .key value.

Ah, in my understanding TextEventDispatcher sets .key value for high-surrogate keypress to the surrogate pair, and one for low-surrogate keypress to empty string. However, it does not do so. Therefore, I need to change TextEventDispatcher too.

A lone surrogate should not appear in DOMString at least when the attribute
values of events.

TextEventDispatcher does not handle surrogate pairs correctly. It should not
split surrogate pairs when it sets KeyboardEvent.key value for avoiding the
problem in some DOM API wrappers, e.g., Rust-running-as-wasm.

Additionally, TextEditor and HTMLEditor should handle keypress events
with .key value if it's available and should not accept a surrogate because
InputEvent.data should not be a surrogate.

Therefore, this patch makes TextEventDispatcher sets a surrogate pair to
.key value if the keypress event is for a high-surrogate and makes the
.key value empty if the keypress event is for a low-surrogate.

(Note that there is a spec issue whether .charCode for keypress should have
a Unicode point or a byte of UTF-16, see https://github.com/w3c/uievents/issues/346)

Finally, this patch makes TextEditor and HTMLEditor handles keypress
events with .key value unless .charCode is neither 0 nor a surrogate but
.key value is empty (this is required for some edge cases like input from
barcode scanner).

This includes source file and binary (installer) of Emoji keyboard layout which is created with Microsoft Keyboard Layout Creator (MSKLC). This types one key stroke as a face mark of Emoji, and the keyboard layout is installed as en-US language's layout.

Attachment #9341187 - Attachment description: Bug 1840519 - Make `keypress` event should not store a surrogate alone within the key value and editors handle it instead of `.charCode` r=m_kato!,smaug! → Bug 1840519 - Make typing surrogate pair behavior switchable with prefs r=m_kato!,smaug!
Pushed by masayuki@d-toybox.com:
https://hg.mozilla.org/integration/autoland/rev/1e0ec5506207
Make typing surrogate pair behavior switchable with prefs r=m_kato,smaug
Summary: `TextEditor` and `HTMLEditor` should handle `keypress` events with `.key` value instead of `.charCode` value → `TextEditor` and `HTMLEditor` should handle `keypress` events with `.key` value instead of `.charCode` value (in early beta builds and nightly builds)
Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 118 Branch
See Also: → 1849865
Regressions: 1849939
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: