Add the command palette, Write formatting keys, and platform labels

Phase 5-2.

- Ctrl+Shift+P opens the command palette: every workbench command with
  its shortcut, then the plugin commands (UI-048).
- In Write, Ctrl+B, Ctrl+I, Ctrl+Shift+X, and Ctrl+Shift+H format the
  selection, and Ctrl+K inserts a Markdown link. The Format menu shows
  these shortcuts.
- Ctrl+\ toggles the side pane. It matches the physical key on every
  keyboard layout. Ctrl+B now belongs to Write.
- Help lists every shortcut in groups, open by default. The list comes
  from the command table.
- src/lib/ui/shortcuts.ts writes shortcut labels for the platform:
  Ctrl+Shift+P on Windows and Linux, and the macOS symbols on a Mac.
  The catalog uses placeholders, so no translation contains "Ctrl".
- 19 new catalog rows, and 10 rows converted to placeholders, in
  French, Japanese, and Simplified Chinese.
- Docs: UI-048, the user guide keyboard tables, and a label rule in
  ui-design.md.

New tests: layout/commands, tests/unit/ui/shortcuts.spec.ts, and new
cases in workbenchKeys.spec.ts. Tests that read the old labels or
pressed Ctrl+B for the side pane now use the new names and Ctrl+\.

The smoke harness raises the resource timing buffer to 5000 entries.
The new modules pushed the CodeMirror language module past the
default 250 entries, so editor/markdownPaste could not find its URL.
This commit is contained in:
Knotty Wyvern
2026-10-28 19:10:25 -07:00
parent b2348d0fe8
commit ebacdb8164
48 changed files with 506 additions and 125 deletions
+2 -1
View File
@@ -35,6 +35,7 @@
import { languageSupport } from "./codeLanguages";
import { indentListItem, outdentListItem } from "./markdownLists";
import { insertIndent, sourceChrome, sourceEditing } from "./sourceView";
import { formatKeymap } from "./formatKeys";
import "./headingFolding.css";
type Mode = "write" | "source";
@@ -155,7 +156,7 @@
return [
headingFolding,
tableNavigation,
keymap.of([{ key: "Escape", run: view => {
keymap.of([...formatKeymap, { key: "Escape", run: view => {
if (!view.state.field(imageSource)) return false;
view.dispatch({ effects: editImageSource.of(null) }); return true;
} }, ...lists, indentWithTab]),
+2 -1
View File
@@ -1,4 +1,5 @@
import { tr } from '../i18n/index.ts';
import { keys } from "../ui/shortcuts";
import { EditorSelection } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import { redo, redoDepth, undo, undoDepth } from "@codemirror/commands";
@@ -38,7 +39,7 @@ export function codeMenu(view: EditorView, report: (message: string) => void) {
};
menu = showActionMenu({ x, y, label: tr("Code text actions"), items: [
...historyItems({ canUndo: undoDepth(state) > 0, canRedo: redoDepth(state) > 0, undo: () => undo(view), redo: () => redo(view) }),
{ label: tr("Change all occurrences"), icon: "select", shortcut: "Ctrl+Shift+L", disabled: !word || word.empty, run: changeAll },
{ label: tr("Change all occurrences"), icon: "select", shortcut: keys("Mod+Shift+L"), disabled: !word || word.empty, run: changeAll },
{ separator: true },
...clipboardItems({
selected: !!selected, cut: () => void clipboard("cut"), copy: () => void clipboard("copy"), paste: () => void clipboard("paste"),
+25
View File
@@ -0,0 +1,25 @@
// Write formatting shortcuts. Each one makes the same edit as its item in the Format menu.
import type { EditorView, KeyBinding } from "@codemirror/view";
import { isolateHistory } from "@codemirror/commands";
import { formatText, type InlineFormat, type MarkdownEdit } from "./markdownCommands";
import { externalLinkText } from "./linkCommands";
/** The shortcut of each format, as written combinations for the menu labels. */
export const FORMAT_KEYS: Partial<Record<InlineFormat, string>> = { bold: "Mod+B", italic: "Mod+I", strike: "Mod+Shift+X", highlight: "Mod+Shift+H" };
export const LINK_KEY = "Mod+K";
function apply(view: EditorView, edit: MarkdownEdit) {
view.dispatch({ changes: { from: edit.from, to: edit.to, insert: edit.insert }, selection: { anchor: edit.anchor, head: edit.head },
userEvent: "input.markdown", annotations: isolateHistory.of("full"), scrollIntoView: true });
return true;
}
const format = (kind: InlineFormat) => (view: EditorView) => apply(view, formatText(view.state.doc.toString(), view.state.selection.main, kind));
export const formatKeymap: KeyBinding[] = [
{ key: "Mod-b", run: format("bold"), preventDefault: true },
{ key: "Mod-i", run: format("italic"), preventDefault: true },
{ key: "Mod-Shift-x", run: format("strike"), preventDefault: true },
{ key: "Mod-Shift-h", run: format("highlight"), preventDefault: true },
{ key: "Mod-k", run: view => apply(view, externalLinkText(view.state.doc.toString(), view.state.selection.main)), preventDefault: true },
];
+6 -2
View File
@@ -1,4 +1,8 @@
import { tr } from '../i18n/index.ts';
import { isMac } from "../ui/shortcuts";
/** The tooltip of a link in Write. A click with Ctrl, or Cmd on macOS, opens the link. */
const linkTooltip = () => tr("{modifier}+click to open link", { modifier: isMac() ? "⌘" : "Ctrl" });
import { EditorSelection, StateEffect, StateField, type EditorState, type Range } from "@codemirror/state";
import { Decoration, EditorView, ViewPlugin, WidgetType, type DecorationSet } from "@codemirror/view";
import { syntaxTree, foldedRanges, foldEffect, unfoldEffect } from "@codemirror/language";
@@ -317,7 +321,7 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
if (!match) return;
replace(node.from, node.from + 1);
replace(node.from + 1 + match[1].length, node.to);
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-href": match[2], "data-kind": "md", "data-editor-tooltip": "Ctrl+click to open link" } }).range(node.from + 1, node.from + 1 + match[1].length));
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-href": match[2], "data-kind": "md", "data-editor-tooltip": linkTooltip() } }).range(node.from + 1, node.from + 1 + match[1].length));
return false;
}
} });
@@ -339,7 +343,7 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
const labelStart = from + 2 + (separator < 0 ? 0 : separator + 1);
replace(from, labelStart);
replace(to - 2, to);
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-kind": "wiki", "data-href": match[1].split("|")[0], "data-editor-tooltip": "Ctrl+click to open link" } }).range(labelStart, to - 2));
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-kind": "wiki", "data-href": match[1].split("|")[0], "data-editor-tooltip": linkTooltip() } }).range(labelStart, to - 2));
}
for (const link of documentLinks(source)) {
if (!selected(link.from, link.to) || hidden(link.from, link.to)) continue;
+4 -2
View File
@@ -10,6 +10,8 @@ import { documentLinkAt } from "./documentLinks";
import { linkMenuItems, type DocumentLinkActions } from "./linkMenu";
import { htmlToMarkdown } from "../workspace/htmlToMarkdown";
import { cellFormats, type TableContextActions } from "./tableCellActions";
import { FORMAT_KEYS, LINK_KEY } from "./formatKeys";
import { keys } from "../ui/shortcuts";
import { formatText, insertBlock, paragraphText, replacement, type MarkdownEdit, type TextSelection, type ParagraphStyle, type InsertBlock } from "./markdownCommands";
export type MarkdownMenuEditor = {
@@ -89,7 +91,7 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
}), { separator: true as const }] : []),
...(editor.undo ? historyItems({ canUndo: !!editor.canUndo?.(), canRedo: !!editor.canRedo?.(), undo: () => editor.undo?.(), redo: () => editor.redo?.() }) : []),
{ label: tr("Add link"), icon: "link", run: () => link(false) },
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
{ label: tr("Add external link"), icon: "external", shortcut: keys(LINK_KEY), run: () => link(true) },
{ separator: true },
searchItem(text, actions.onSearch),
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
@@ -98,7 +100,7 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
}) },
{ label: tr("Format"), icon: "format", children: cellFormats.flatMap(([label, kind]) => [
...(kind === "code" || kind === "clear" ? [{ separator: true } as const] : []),
{ label: tr(label), icon: kind, disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
{ label: tr(label), icon: kind, ...(FORMAT_KEYS[kind] ? { shortcut: keys(FORMAT_KEYS[kind]) } : {}), disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
]) },
{ label: tr("Paragraph"), icon: "paragraph", children: [
paragraph(tr("Bullet list"), "bullet", "bullet"), paragraph(tr("Numbered list"), "number", "number"), paragraph(tr("Task list"), "task", "task"),
+2 -1
View File
@@ -1,4 +1,5 @@
import { tr } from '../i18n/index.ts';
import { keys } from "../ui/shortcuts";
import type { ActionMenuItem } from "../ui/actionMenu";
import { showActionMenu, type MenuHandle } from "../ui/managedActionMenu";
import { clipboardItems, searchItem } from "../ui/menuItems";
@@ -30,7 +31,7 @@ export function readingMenu(host: HTMLElement, actions: DocumentLinkActions, sea
previousFocus = document.activeElement instanceof HTMLElement && host.contains(document.activeElement) ? document.activeElement : host;
const items: ActionMenuItem[] = [];
if (text) items.push(
...clipboardItems({ selected: true, copy: () => void navigator.clipboard.writeText(text).catch(() => report(tr("Clipboard unavailable. Use Ctrl+C to copy."))) }),
...clipboardItems({ selected: true, copy: () => void navigator.clipboard.writeText(text).catch(() => report(tr("Clipboard unavailable. Use {shortcut} to copy.", { shortcut: keys("Mod+C") }))) }),
searchItem(text, search),
);
if (anchor) {
+1 -1
View File
@@ -275,7 +275,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
next.scrollIntoView({ block: "nearest", inline: "nearest" });
return true;
}
// Keep formatting shortcuts local; the workbench also binds Ctrl+B.
// Keep formatting shortcuts in the cell. The Writer around the table also binds Ctrl+B.
if ((event.ctrlKey || event.metaKey) && ["b", "i"].includes(event.key.toLowerCase())) event.stopPropagation();
if ((event.ctrlKey || event.metaKey) && (event.key === "Home" || event.key === "End")) {
event.preventDefault(); event.stopPropagation();
+2 -1
View File
@@ -1,4 +1,5 @@
import { tr } from '../i18n/index.ts';
import { keys } from "../ui/shortcuts";
import type { EditorView } from "@codemirror/view";
import { isolateHistory, redo, undo } from "@codemirror/commands";
import type { Editor } from "@tiptap/core";
@@ -87,7 +88,7 @@ export function tableSelectionControls(root: HTMLElement, wrapper: HTMLElement,
}
} catch {
const status = root.querySelector<HTMLElement>(".table-edit-help");
if (status) { status.hidden = false; status.setAttribute("role", "status"); status.textContent = `Clipboard unavailable here. Use ${navigator.platform.includes("Mac") ? "⌘" : "Ctrl"}+${action === "paste" ? "V" : action === "cut" ? "X" : "C"}.`; }
if (status) { status.hidden = false; status.setAttribute("role", "status"); status.textContent = tr("Clipboard unavailable here. Use {shortcut}.", { shortcut: keys(`Mod+${action === "paste" ? "V" : action === "cut" ? "X" : "C"}`) }); }
}
}
function showMenu(x: number, y: number, at = range?.head, textEditor?: Editor) {