Use one menu lifecycle and shared menu rows in the editors

Phase 4c. The Markdown, code, Read, and image menus open through
showActionMenu. It closes a menu on an outside press, an outside scroll,
a resize, and window blur. A host surface now gives its own focus
return, so four copies of the listener code are gone.

- menuItems.ts builds Undo, Redo, the clipboard rows, and the search
  row. The Markdown, code, Read, table cell, and table range menus use
  it. The Markdown and table menus now show the shortcuts for Cut,
  Copy, Paste, and Select all, as the other menus did.
- writerSearch.ts is now editorSearch.ts, because it serves Write and
  Source.
- Plugins still get only close() from api.ui.showActionMenu. The SDK
  menu types do not change.
- The table range menu and the native spelling menu keep their own
  lifecycle, because their open state drives table editing and the
  native spelling protocol.
- docs/ui-design.md names the shared rows and the search modules. The
  menu inventory has the new count for markdownMenu.ts.

pnpm check, pnpm test (341 of 341), and the full smoke suite pass, except
tables/formulas, which failed one time under load and passed on retry.
This commit is contained in:
Knotty Wyvern
2026-10-28 11:09:09 -07:00
parent 724402729e
commit 6cd9195370
17 changed files with 152 additions and 135 deletions
+3 -3
View File
@@ -35,9 +35,9 @@ await runSmoke("editor/emptyMenu", async ({ page }) => {
await setSource('');
await page.locator('.cm-line').first().click({button:'right'});
await menu().waitFor();
for (const label of ['Add link','Add external link','Format','Paragraph','Insert','Paste','Paste as plain text','Select all']) assert.equal(await menu().getByRole('menuitem', {name:label,exact:true}).count(),1,label);
assert.equal(await menu().getByRole('menuitem',{name:'Cut',exact:true}).isDisabled(),true);
assert.equal(await menu().getByRole('menuitem',{name:'Copy',exact:true}).isDisabled(),true);
for (const label of ['Add link','Add external link','Format','Paragraph','Insert','Paste Ctrl+V','Paste as plain text','Select all Ctrl+A']) assert.equal(await menu().getByRole('menuitem', {name:label,exact:true}).count(),1,label);
assert.equal(await menu().getByRole('menuitem',{name:'Cut Ctrl+X',exact:true}).isDisabled(),true);
assert.equal(await menu().getByRole('menuitem',{name:'Copy Ctrl+C',exact:true}).isDisabled(),true);
await page.screenshot({path:`${output}/empty-${theme}.png`});
await menu().getByRole('menuitem',{name:'Format',exact:true}).focus();
await page.keyboard.press('ArrowRight');
+1 -1
View File
@@ -49,7 +49,7 @@ await runSmoke("editor/surfaces", async ({ page }) => {
await text.click({ button: 'right', position: { x: 20, y: 8 } });
const writer = menu('Markdown text actions');
assert.deepEqual(await styles(writer), reference);
for (const name of ['Add link', 'Add external link', 'Format', 'Paragraph', 'Insert', 'Paste', 'Select all']) assert.equal(await item(name).count(), 1);
for (const name of ['Add link', 'Add external link', 'Format', 'Paragraph', 'Insert', 'Paste Ctrl+V', 'Select all Ctrl+A']) assert.equal(await item(name).count(), 1);
await item('Corrected').waitFor();
assert.equal(await item('Spelling').count(), 0, 'Corrections appear directly in the main menu');
assert.equal(await writer.locator(':scope > button').first().textContent(), 'Corrected');
+3 -3
View File
@@ -44,8 +44,8 @@ await runSmoke("find/searchPanel", async ({ page }) => {
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
await find.waitFor();
assert.equal(await find.evaluate(el => document.activeElement === el), true);
assert.equal(await page.locator(".cm-panels-top .rs-writer-search").count(), 1);
const panelBounds = await page.locator(".rs-writer-search").boundingBox();
assert.equal(await page.locator(".cm-panels-top .rs-editor-search").count(), 1);
const panelBounds = await page.locator(".rs-editor-search").boundingBox();
const scrollBounds = await page.locator(".cm-scroller").boundingBox();
assert.ok(panelBounds.y + panelBounds.height <= scrollBounds.y + 1);
await find.fill("Alpha");
@@ -110,7 +110,7 @@ await runSmoke("find/searchPanel", async ({ page }) => {
await page.setViewportSize({ width: 880, height: 760 });
await find.focus();
await page.screenshot({ path: path.join(output, "find-bars-narrow.png") });
for (const selector of [".rs-writer-search", ".outline-search"]) {
for (const selector of [".rs-editor-search", ".outline-search"]) {
assert.equal(await page.locator(selector).evaluate(el => el.scrollWidth <= el.clientWidth), true, selector);
}
console.log("PASS: Top search panel, shortcuts, replacement, query sync, invalid regex, focus tooltip, outline filtering, focus return and narrow layout.");
+8 -8
View File
@@ -497,12 +497,12 @@ await runSmoke("layout/workbench", async ({ page }) => {
}
await cellAction('Clear formatting', true);
await page.waitForFunction(() => document.querySelectorAll('.live-writer table strong').length === 0);
await cellAction('Copy');
await cellAction('Copy Ctrl+C');
// clipboard.write resolves its items asynchronously.
await page.waitForFunction(expected => window.__TEST__.clipboard === expected, 'one\ttwo\nfour\tfive');
await cellAction('Cut');
await cellAction('Cut Ctrl+X');
await page.waitForFunction(() => [...document.querySelectorAll('.is-cell-selected')].every(cell => !cell.textContent.trim()));
await cellAction('Paste');
await cellAction('Paste Ctrl+V');
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'one');
await cellAction('Align centre');
await page.waitForFunction(() => [...document.querySelectorAll('.is-cell-selected')].every(cell => cell.style.textAlign === 'center'));
@@ -617,7 +617,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
}
await selectBrokers();
await actionCell(1, 0).click({ button: 'right' });
assert.equal(await page.getByRole('menuitem', { name: 'Copy', exact: true }).isDisabled(), false);
assert.equal(await page.getByRole('menuitem', { name: 'Copy Ctrl+C', exact: true }).isDisabled(), false);
assert.ok(await page.locator('.table-cell-menu button').evaluateAll(buttons => buttons.every(button => button.querySelector('svg[aria-hidden="true"]'))));
await page.getByRole('menuitem', { name: 'Row', exact: true }).hover();
await page.screenshot({ path: path.join(output, 'table-text-row-menu.png') });
@@ -666,18 +666,18 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.evaluate(() => {
navigator.clipboard.read = async () => [{ types: ['text/html', 'text/plain'], getType: async type => new Blob([type === 'text/html' ? '<em>Rich paste</em>' : 'Rich paste'], { type }) }];
});
await actionItem('Paste');
await actionItem('Paste Ctrl+V');
await page.waitForFunction(() => document.querySelector('.live-writer td em')?.textContent === 'Rich paste');
await page.keyboard.press('Control+z');
await page.evaluate(() => { delete navigator.clipboard.read; });
await selectBrokers();
await actionItem('Copy');
await actionItem('Copy Ctrl+C');
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), 'Brokers');
await actionItem('Cut');
await actionItem('Cut Ctrl+X');
await page.waitForFunction(() => !document.querySelector('.live-writer td').textContent.includes('Brokers'));
await page.keyboard.press('Control+z');
await selectBrokers();
await actionItem('Select all');
await actionItem('Select all Ctrl+A');
assert.equal(await page.evaluate(() => getSelection().toString()), 'Interactive Brokers Group');
await page.setViewportSize({ width: 800, height: 600 });
await actionCell(1, 0).click({ button: 'right' });