Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: support undo/redo editing commands (#13606)

Andrey Lushnikov80bc532874bd
diff --git a/packages/playwright-core/src/server/macEditingCommands.ts b/packages/playwright-core/src/server/macEditingCommands.ts
index 8f4c496e8a..c6de45d462 100644
--- a/packages/playwright-core/src/server/macEditingCommands.ts
+++ b/packages/playwright-core/src/server/macEditingCommands.ts
@@ -128,4 +128,6 @@ export const macEditingCommands: {[key: string]: string|string[]} = {
'Meta+KeyA': 'selectAll:',
'Meta+KeyC': 'copy:',
'Meta+KeyV': 'paste:',
+ 'Meta+KeyZ': 'undo:',
+ 'Shift+Meta+KeyZ': 'redo:',
};
diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts
index e0f45dd23d..32a4134ca3 100644
--- a/tests/page/page-keyboard.spec.ts
+++ b/tests/page/page-keyboard.spec.ts
@@ -476,6 +476,20 @@ it('should support simple copy-pasting', async ({ page, isMac, browserName }) =>
expect(await page.evaluate(() => document.querySelector('div').textContent)).toBe('123123');
});
+it('should support undo-redo', async ({ page, isMac, browserName, isLinux }) => {
+ it.fixme(browserName === 'webkit' && isLinux, 'https://github.com/microsoft/playwright/issues/12000');
+ const modifier = isMac ? 'Meta' : 'Control';
+ await page.setContent(`<div contenteditable></div>`);
+ const div = page.locator('div');
+ await expect(div).toHaveText('');
+ await div.type('123');
+ await expect(div).toHaveText('123');
+ await page.keyboard.press(`${modifier}+KeyZ`);
+ await expect(div).toHaveText('');
+ await page.keyboard.press(`Shift+${modifier}+KeyZ`);
+ await expect(div).toHaveText('123');
+});
+
it('should type repeatedly in contenteditable in shadow dom', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/12941' });