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> { async keyup(modifiers: Set<types.KeyboardModifier>, code: string, keyCode: number, keyCodeWithoutLocation: number, key: string, location: number): Promise<void> {
const actions: bidi.Input.KeySourceAction[] = []; const actions: bidi.Input.KeySourceAction[] = [];
actions.push({ type: 'keyUp', value: getBidiKeyValue(key) }); actions.push({ type: 'keyUp', value: getBidiKeyValue(code) });
await this._performActions(actions); await this._performActions(actions);
} }

View file

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