feat(keyboard): support simple copy-pasting using meta+c/v (#10828)

It's a straightforward change to support new, common, keyboard commands

Note that I've tested this locally with Chrome on my Mac but it seems that CI doesn't want to pass Chrome tests - it's running on ubuntu though. Does this mean that I should introduce per-platform editing commands? At the moment there is only a single [`macEditingCommands`](0ed33522c5/packages/playwright-core/src/server/macEditingCommands.ts) file.

References https://github.com/microsoft/playwright/issues/12000

Co-authored-by: Andrey Lushnikov <aslushnikov@gmail.com>
This commit is contained in:
Mateusz Burzyński 2022-02-28 22:43:43 +01:00 committed by GitHub
parent f47423d315
commit eaa98ce53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -126,4 +126,6 @@ export const macEditingCommands: {[key: string]: string|string[]} = {
'Shift+Meta+ArrowRight': 'moveToRightEndOfLineAndModifySelection:',
'Meta+KeyA': 'selectAll:',
'Meta+KeyC': 'copy:',
'Meta+KeyV': 'paste:',
};

View File

@ -464,6 +464,18 @@ it('should dispatch a click event on a button when Enter gets pressed', async ({
expect((await actual.jsonValue()).clicked).toBe(true);
});
it('should support simple copy-pasting', async ({ page, isMac, browserName }) => {
it.fixme(browserName === 'webkit', 'https://github.com/microsoft/playwright/issues/12000');
const modifier = isMac ? 'Meta' : 'Control';
await page.setContent(`<div contenteditable>123</div>`);
await page.focus('div');
await page.keyboard.press(`${modifier}+KeyA`);
await page.keyboard.press(`${modifier}+KeyC`);
await page.keyboard.press(`${modifier}+KeyV`);
await page.keyboard.press(`${modifier}+KeyV`);
expect(await page.evaluate(() => document.querySelector('div').textContent)).toBe('123123');
});
async function captureLastKeydown(page) {
const lastEvent = await page.evaluateHandle(() => {
const lastEvent = {