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:
@@ -3,6 +3,7 @@ import { getMarkRange, type Editor, type JSONContent } from "@tiptap/core";
|
||||
import { requestText } from "../workspace/dialogs.svelte";
|
||||
import { extractedCellMarkdown } from "./tableCellMarkdown";
|
||||
import type { ActionMenuItem } from "../ui/actionMenu";
|
||||
import { clipboardItems, searchItem } from "../ui/menuItems";
|
||||
import { linkMenuItems, type DocumentLinkActions } from "./linkMenu";
|
||||
import { documentLinkAt } from "./documentLinks";
|
||||
|
||||
@@ -97,7 +98,7 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
|
||||
{ label: tr("Add link"), icon: "link", run: () => link(false) },
|
||||
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
|
||||
{ separator: true },
|
||||
{ label: text ? tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }) : tr("Search selection"), icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
|
||||
searchItem(text, actions.onSearch && (value => { close(); actions.onSearch?.(value); })),
|
||||
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
|
||||
const selected = doc.slice(selection.from, selection.to).content.toJSON() as JSONContent[] | null;
|
||||
const markdown = extractedCellMarkdown(selected || []);
|
||||
@@ -110,11 +111,10 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
|
||||
{ label: tr("Paragraph"), icon: "paragraph", disabled: true, title: tr("Markdown table cells contain inline text") },
|
||||
{ label: tr("Insert"), icon: "insert", disabled: true, title: tr("Use the Row and Column menus to change the table") },
|
||||
{ separator: true },
|
||||
{ label: tr("Cut"), icon: "cut", disabled: selection.empty, run: () => void clipboard("cut") },
|
||||
{ label: tr("Copy"), icon: "copy", disabled: selection.empty, run: () => void clipboard("copy") },
|
||||
{ label: tr("Paste"), icon: "paste", run: () => void clipboard("paste") },
|
||||
{ label: tr("Paste as plain text"), icon: "paste-text", run: () => void clipboard("plain") },
|
||||
{ label: tr("Select all"), icon: "select", run: () => { close(); editor.commands.selectAll(); editor.view.focus(); } },
|
||||
...clipboardItems({
|
||||
selected: !selection.empty, cut: () => void clipboard("cut"), copy: () => void clipboard("copy"), paste: () => void clipboard("paste"),
|
||||
pastePlain: () => void clipboard("plain"), selectAll: () => { close(); editor.commands.selectAll(); editor.view.focus(); },
|
||||
}),
|
||||
];
|
||||
return sourceEditing ? [
|
||||
...(selectedLink ? [...linkMenuItems(selectedLink, actions.linkActions?.() || {}, close, report, editLink), { separator: true as const }] : []),
|
||||
|
||||
Reference in New Issue
Block a user