LibWeb: Allow multi-byte code point events to have their key field set
Multi-byte code point presses do not have a UIEvents::KeyCode value, so we would previously set the event's key field to "Unidentified".
This commit is contained in:
parent
96b5646fc1
commit
a11e5055c7
Notes:
github-actions[bot]
2024-10-10 08:42:21 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/a11e5055c7f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1706
3 changed files with 34 additions and 8 deletions
|
@ -0,0 +1,6 @@
|
|||
keydown à
|
||||
keydown á
|
||||
keydown â
|
||||
keydown ã
|
||||
keydown ä
|
||||
keydown å
|
18
Tests/LibWeb/Text/input/UIEvents/KeyEvent-non-ascii.html
Normal file
18
Tests/LibWeb/Text/input/UIEvents/KeyEvent-non-ascii.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<input id="input" />
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let input = document.getElementById("input");
|
||||
|
||||
input.addEventListener("keydown", e => {
|
||||
println(`keydown ${e.key}`);
|
||||
});
|
||||
|
||||
internals.sendText(input, "à");
|
||||
internals.sendText(input, "á");
|
||||
internals.sendText(input, "â");
|
||||
internals.sendText(input, "ã");
|
||||
internals.sendText(input, "ä");
|
||||
internals.sendText(input, "å");
|
||||
});
|
||||
</script>
|
|
@ -272,18 +272,22 @@ static ErrorOr<String> get_event_key(KeyCode platform_key, u32 code_point)
|
|||
{
|
||||
// 1. Let key be a DOMString initially set to "Unidentified".
|
||||
// NOTE: We return "Unidentified" at the end to avoid needlessly allocating it here.
|
||||
Optional<String> key;
|
||||
|
||||
// 2. If there exists an appropriate named key attribute value for this key event, then
|
||||
if (auto named_key = TRY(get_event_named_key(platform_key)); named_key.has_value()) {
|
||||
// 1. Set key to that named key attribute value.
|
||||
key = named_key.release_value();
|
||||
// AD-HOC: Key_Invalid would be interpreted as "Unidentified" here. But we also use Key_Invalid for key presses that
|
||||
// are not on a standard US keyboard. If such a key would generate a valid key string below, let's allow that
|
||||
// to happen; otherwise, we will still return "Unidentified" at the end.
|
||||
if (platform_key != KeyCode::Key_Invalid) {
|
||||
if (auto named_key = TRY(get_event_named_key(platform_key)); named_key.has_value()) {
|
||||
// 1. Set key to that named key attribute value.
|
||||
return named_key.release_value();
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Else, if the key event generates a valid key string, then
|
||||
else if (auto key_string = TRY(get_event_key_string(code_point)); key_string.has_value()) {
|
||||
if (auto key_string = TRY(get_event_key_string(code_point)); key_string.has_value()) {
|
||||
// 1. Set key to that key string value.
|
||||
key = key_string.release_value();
|
||||
return key_string.release_value();
|
||||
}
|
||||
|
||||
// FIXME: 4. Else, if the key event has any modifier keys other than glyph modifier keys, then
|
||||
|
@ -291,8 +295,6 @@ static ErrorOr<String> get_event_key(KeyCode platform_key, u32 code_point)
|
|||
// modifer keys removed except for glyph modifier keys.
|
||||
|
||||
// 5. Return key as the key attribute value for this key event.
|
||||
if (key.has_value())
|
||||
return key.release_value();
|
||||
return "Unidentified"_string;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue