Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bidi): propertly dispatch ControlRight key event #34246

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/bidi/bidiInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class RawKeyboardImpl implements input.RawKeyboard {

async keydown(modifiers: Set<types.KeyboardModifier>, code: string, keyCode: number, keyCodeWithoutLocation: number, key: string, location: number, autoRepeat: boolean, text: string | undefined): Promise<void> {
const actions: bidi.Input.KeySourceAction[] = [];
actions.push({ type: 'keyDown', value: getBidiKeyValue(key) });
actions.push({ type: 'keyDown', value: getBidiKeyValue(code) });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall getBidiKeyValue = (key: string) be as well get updated to reflect that code has to be passed in and not key? That explains why I didn't find the problem. Thanks for fixing it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, renaming makes sense, feel free to send a PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the function has been copied from puppeteer)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #34286 for that which also includes the same fix for keyup, which you missed here.

// TODO: add modifiers?
await this._performActions(actions);
}
Expand Down
16 changes: 12 additions & 4 deletions tests/page/page-keyboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,24 @@ it('should specify location', async ({ page, server }) => {
const textarea = await page.$('textarea');

await textarea.press('Digit5');
expect(await lastEvent.evaluate(e => e.location)).toBe(0);
expect.soft(await lastEvent.evaluate(e => e.location)).toBe(0);
expect.soft(await lastEvent.evaluate(e => e.key)).toBe('5');
expect.soft(await lastEvent.evaluate(e => e.code)).toBe('Digit5');

await textarea.press('ControlLeft');
expect(await lastEvent.evaluate(e => e.location)).toBe(1);
expect.soft(await lastEvent.evaluate(e => e.location)).toBe(1);
expect.soft(await lastEvent.evaluate(e => e.key)).toBe('Control');
expect.soft(await lastEvent.evaluate(e => e.code)).toBe('ControlLeft');

await textarea.press('ControlRight');
expect(await lastEvent.evaluate(e => e.location)).toBe(2);
expect.soft(await lastEvent.evaluate(e => e.location)).toBe(2);
expect.soft(await lastEvent.evaluate(e => e.key)).toBe('Control');
expect.soft(await lastEvent.evaluate(e => e.code)).toBe('ControlRight');

await textarea.press('NumpadSubtract');
expect(await lastEvent.evaluate(e => e.location)).toBe(3);
expect.soft(await lastEvent.evaluate(e => e.location)).toBe(3);
expect.soft(await lastEvent.evaluate(e => e.key)).toBe('-');
expect.soft(await lastEvent.evaluate(e => e.code)).toBe('NumpadSubtract');
});

it('should press Enter', async ({ page, server }) => {
Expand Down
Loading