mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
LibWeb: Fire keypress event for Enter, Shift+Enter, and Ctrl+Enter keys
For web compat and interop with other engines, this change makes us fire “keypress” events for the Enter key and for the combination of the Enter key with the Shift or Ctrl keys — despite the fact the UI Events spec states at https://w3c.github.io/uievents/#event-type-keypress it must be fired “if and only if that key normally produces a character value”. See https://github.com/w3c/uievents/issues/183#issuecomment-448091687 and https://github.com/w3c/uievents/issues/266#issuecomment-1887917756.
This commit is contained in:
committed by
Sam Atkins
parent
be38acfad9
commit
738cb24691
Notes:
github-actions[bot]
2025-01-31 12:08:14 +00:00
Author: https://github.com/sideshowbarker Commit: https://github.com/LadybirdBrowser/ladybird/commit/738cb246910 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3353 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/Gingeh ✅
@@ -4,15 +4,39 @@
|
||||
test(() => {
|
||||
let input = document.getElementById("input");
|
||||
|
||||
const modifierKeys = ['Alt', 'Control', 'Shift', 'Super', 'NumLock'];
|
||||
input.addEventListener("keydown", e => {
|
||||
println(`keydown key=${e.key} charCode=${e.charCode}`);
|
||||
const activeModifiers = modifierKeys.filter(modifier => e.getModifierState(modifier));
|
||||
if (activeModifiers.length > 0) {
|
||||
println(`keydown key=${e.key} charCode=${e.charCode} modifiers=${activeModifiers.join(', ')}`);
|
||||
} else {
|
||||
println(`keydown key=${e.key} charCode=${e.charCode}`);
|
||||
}
|
||||
});
|
||||
input.addEventListener("keypress", e => {
|
||||
println(`keypress key=${e.key} charCode=${e.charCode}`);
|
||||
const activeModifiers = modifierKeys.filter(modifier => e.getModifierState(modifier));
|
||||
if (activeModifiers.length > 0) {
|
||||
println(`keypress key=${e.key} charCode=${e.charCode} modifiers=${activeModifiers.join(', ')}`);
|
||||
} else {
|
||||
println(`keypress key=${e.key} charCode=${e.charCode}`);
|
||||
}
|
||||
});
|
||||
|
||||
internals.sendText(input, "A");
|
||||
internals.sendKey(input, "LeftShift");
|
||||
internals.sendText(input, "B");
|
||||
|
||||
internals.sendKey(input, "Return");
|
||||
|
||||
let modifiers = 1 << 0; // Mod_Alt
|
||||
internals.sendKey(input, "Return", modifiers);
|
||||
modifiers = 1 << 1; // Mod_Ctrl
|
||||
internals.sendKey(input, "Return", modifiers);
|
||||
modifiers = 1 << 2; // Mod_Shift
|
||||
internals.sendKey(input, "Return", modifiers);
|
||||
modifiers = 1 << 3; // Mod_Super
|
||||
internals.sendKey(input, "Return", modifiers);
|
||||
modifiers = 1 << 4; // Mod_Keypad
|
||||
internals.sendKey(input, "Return", modifiers);
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user