Improve WebDriver BiDi key codes (#34286)

This commit is contained in:
Henrik Skupin 2025-01-10 18:19:28 +01:00 committed by GitHub
parent a2e2dfd446
commit 89172175d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -40,7 +40,7 @@ export class RawKeyboardImpl implements input.RawKeyboard {
async keyup(modifiers: Set<types.KeyboardModifier>, code: string, keyCode: number, keyCodeWithoutLocation: number, key: string, location: number): Promise<void> {
const actions: bidi.Input.KeySourceAction[] = [];
actions.push({ type: 'keyUp', value: getBidiKeyValue(key) });
actions.push({ type: 'keyUp', value: getBidiKeyValue(code) });
await this._performActions(actions);
}

View File

@ -7,18 +7,18 @@
/* eslint-disable curly */
export const getBidiKeyValue = (key: string) => {
switch (key) {
export const getBidiKeyValue = (code: string) => {
switch (code) {
case '\r':
case '\n':
key = 'Enter';
code = 'Enter';
break;
}
// Measures the number of code points rather than UTF-16 code units.
if ([...key].length === 1) {
return key;
if ([...code].length === 1) {
return code;
}
switch (key) {
switch (code) {
case 'Cancel':
return '\uE001';
case 'Help':
@ -131,6 +131,8 @@ export const getBidiKeyValue = (key: string) => {
return '\uE052';
case 'MetaRight':
return '\uE053';
case 'Space':
return ' ';
case 'Digit0':
return '0';
case 'Digit1':
@ -226,6 +228,6 @@ export const getBidiKeyValue = (key: string) => {
case 'Quote':
return '"';
default:
throw new Error(`Unknown key: "${key}"`);
throw new Error(`Unknown key: "${code}"`);
}
};