diff --git a/docs/menu-surfaces.json b/docs/menu-surfaces.json
index 37ff720..170ef83 100644
--- a/docs/menu-surfaces.json
+++ b/docs/menu-surfaces.json
@@ -80,13 +80,6 @@
"design": "Shared action menu",
"check": "tests/smoke/menus/consistency.smoke.mjs; tests/smoke/links/linkEditing.smoke.mjs; tests/smoke/editor/surfaces.smoke.mjs"
},
- "RuneStone/src/lib/editor/WriterHost.svelte": {
- "counts": {
- "svelteMenu": 1
- },
- "design": "Shared action menu",
- "check": "tests/smoke/menus/consistency.smoke.mjs; tests/smoke/links/linkEditing.smoke.mjs; tests/smoke/editor/surfaces.smoke.mjs"
- },
"RuneStone/src/lib/layout/ContextMenu.svelte": {
"counts": {
"action": 1
diff --git a/package.json b/package.json
index b7b3cea..84298b1 100644
--- a/package.json
+++ b/package.json
@@ -38,14 +38,6 @@
"@tiptap/extension-highlight": "^3.31.3",
"@tiptap/extension-image": "^3.31.3",
"@tiptap/extension-link": "^3.31.3",
- "@tiptap/extension-subscript": "^3.31.3",
- "@tiptap/extension-superscript": "^3.31.3",
- "@tiptap/extension-table": "^3.31.3",
- "@tiptap/extension-table-cell": "^3.31.3",
- "@tiptap/extension-table-header": "^3.31.3",
- "@tiptap/extension-table-row": "^3.31.3",
- "@tiptap/extension-task-item": "^3.31.3",
- "@tiptap/extension-task-list": "^3.31.3",
"@tiptap/pm": "^3.31.3",
"@tiptap/starter-kit": "^3.31.3",
"markdown-it": "^15.0.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7f2106b..f855d67 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -47,30 +47,6 @@ importers:
'@tiptap/extension-link':
specifier: ^3.31.3
version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
- '@tiptap/extension-subscript':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
- '@tiptap/extension-superscript':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
- '@tiptap/extension-table':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
- '@tiptap/extension-table-cell':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))
- '@tiptap/extension-table-header':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))
- '@tiptap/extension-table-row':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))
- '@tiptap/extension-task-item':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/extension-list@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))
- '@tiptap/extension-task-list':
- specifier: ^3.31.3
- version: 3.31.3(@tiptap/extension-list@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))
'@tiptap/pm':
specifier: ^3.31.3
version: 3.31.3
@@ -569,49 +545,6 @@ packages:
peerDependencies:
'@tiptap/core': 3.31.3
- '@tiptap/extension-subscript@3.31.3':
- resolution: {integrity: sha512-jUMMtg4QF7wIXIvsgBmgJjdQMETOX4KMF+Nl/0nuCKs59lEi1StOJzkiEdm+UbFhxvvY9B30uLVgzogGIlHHyg==}
- peerDependencies:
- '@tiptap/core': 3.31.3
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-superscript@3.31.3':
- resolution: {integrity: sha512-WzM84fb8akg1Ni2b1DcE1pE2kkWLbkEVxN2DKElzCVk/kuSNp+VKqOjunHGTnO+kJhXdcmXTVqAO4Vp2kiDxMQ==}
- peerDependencies:
- '@tiptap/core': 3.31.3
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-table-cell@3.31.3':
- resolution: {integrity: sha512-5nueKR/p/IX6B4etWqHjyRsjNfDf6dJZaRgfw1/1l90CJe2h3tTZk4JbUKWN3Mo4FzZuYKzmU3fxcZ8pSVOeJQ==}
- peerDependencies:
- '@tiptap/extension-table': 3.31.3
-
- '@tiptap/extension-table-header@3.31.3':
- resolution: {integrity: sha512-sstVtNQiBYX4P16vlhwBYPsthxDnodHWQfGq0EUQM40Z7H796Lgh9t1qYtu8yARQuHKzvINRwJCSy6DZ8YTDtQ==}
- peerDependencies:
- '@tiptap/extension-table': 3.31.3
-
- '@tiptap/extension-table-row@3.31.3':
- resolution: {integrity: sha512-up6tDK+hYVTFDeJ3XqKO0WJqBzyXNfGxMoimo5h83jrq9dcNh0oPCOzglZ7rdo8GH9I3VJ2fNKxxU2Eg2HcMoQ==}
- peerDependencies:
- '@tiptap/extension-table': 3.31.3
-
- '@tiptap/extension-table@3.31.3':
- resolution: {integrity: sha512-7cnVPHhdiGGeauYqca6JVyPLTqZbqFEEk9nn2e2E8+fBo6zVtV07AktJBqth/XEzjZxcUmGxjoeuWYAisWjUHg==}
- peerDependencies:
- '@tiptap/core': 3.31.3
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-task-item@3.31.3':
- resolution: {integrity: sha512-gCWvvXsCzi9tVFXPqKlkbU81XxtIdfjGy7FM9QFRKiWAvq5uv+Q5nvwrCyMVyP4bA7zRGWFaPzwjL68djgzoBw==}
- peerDependencies:
- '@tiptap/extension-list': 3.31.3
-
- '@tiptap/extension-task-list@3.31.3':
- resolution: {integrity: sha512-3WgVzmfEnDbmxbjUBlvTiKpT53KSBnnYhXUVQxM0nz1vpoWG8QifhsnCVsNI6TZmhgR0x/jY+UW9Hc/WLF8DkQ==}
- peerDependencies:
- '@tiptap/extension-list': 3.31.3
-
'@tiptap/extension-text@3.31.3':
resolution: {integrity: sha512-gdsWtF+taeaCu6V+5Ct10fGo0ACUy1GnYtbb+mcathBt8OqbT+Ws60p/yEmKesBDz2Hn+B5IcWy6+2BBZl5ZTg==}
peerDependencies:
@@ -1825,41 +1758,6 @@ snapshots:
dependencies:
'@tiptap/core': 3.31.3(@tiptap/pm@3.31.3)
- '@tiptap/extension-subscript@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)':
- dependencies:
- '@tiptap/core': 3.31.3(@tiptap/pm@3.31.3)
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-superscript@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)':
- dependencies:
- '@tiptap/core': 3.31.3(@tiptap/pm@3.31.3)
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-table-cell@3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))':
- dependencies:
- '@tiptap/extension-table': 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
-
- '@tiptap/extension-table-header@3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))':
- dependencies:
- '@tiptap/extension-table': 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
-
- '@tiptap/extension-table-row@3.31.3(@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))':
- dependencies:
- '@tiptap/extension-table': 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
-
- '@tiptap/extension-table@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)':
- dependencies:
- '@tiptap/core': 3.31.3(@tiptap/pm@3.31.3)
- '@tiptap/pm': 3.31.3
-
- '@tiptap/extension-task-item@3.31.3(@tiptap/extension-list@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))':
- dependencies:
- '@tiptap/extension-list': 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
-
- '@tiptap/extension-task-list@3.31.3(@tiptap/extension-list@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))':
- dependencies:
- '@tiptap/extension-list': 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
-
'@tiptap/extension-text@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))':
dependencies:
'@tiptap/core': 3.31.3(@tiptap/pm@3.31.3)
diff --git a/src/lib/editor/WriterHost.svelte b/src/lib/editor/WriterHost.svelte
deleted file mode 100644
index 8240670..0000000
--- a/src/lib/editor/WriterHost.svelte
+++ /dev/null
@@ -1,286 +0,0 @@
-
-
-
{
- if (imageFiles(event.dataTransfer).length > 0) {
- event.preventDefault();
- }
- }}
- ondrop={(event) => {
- const files = imageFiles(event.dataTransfer);
- if (files.length === 0 || !onInsertImage) {
- return;
- }
- event.preventDefault();
- void (async () => {
- for (const file of files) {
- const snippet = await onInsertImage(file);
- const rel = snippet ? /\(([^)]+)\)/.exec(snippet)?.[1] : null;
- if (!rel || !editor) {
- continue;
- }
- try {
- const src = await workspaceReadDataUrl(rel);
- editor.commands.insertContent(
- `

`,
- );
- } catch {
- editor.commands.insertContent(snippet);
- }
- }
- })();
- }}
->
-
-{#if menu}
- (menu = null)}
- />
-{/if}
-
-
diff --git a/src/lib/editor/headingMarks.ts b/src/lib/editor/headingMarks.ts
deleted file mode 100644
index 1b6cf96..0000000
--- a/src/lib/editor/headingMarks.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import { Extension } from "@tiptap/core";
-import type { Node as PmNode } from "@tiptap/pm/model";
-import { Plugin, PluginKey } from "@tiptap/pm/state";
-import { Decoration, DecorationSet } from "@tiptap/pm/view";
-
-export function headingMarkText(level: number): string {
- const n = Math.min(6, Math.max(1, Math.floor(level)));
- return "#".repeat(n);
-}
-
-export function fenceOpenText(lang: string): string {
- const name = lang.trim();
- return name ? `\`\`\`${name}` : "```";
-}
-
-export function findInlineCodeRange(doc: PmNode, pos: number): { from: number; to: number } | null {
- const $pos = doc.resolve(pos);
- const type = doc.type.schema.marks.code;
- if (!type || !$pos.parent.inlineContent) {
- return null;
- }
- const parentStart = $pos.start();
- let runFrom = -1;
- let runTo = -1;
- let hit: { from: number; to: number } | null = null;
- $pos.parent.forEach((child, offset) => {
- const from = parentStart + offset;
- const to = from + child.nodeSize;
- if (type.isInSet(child.marks)) {
- if (runFrom === -1) {
- runFrom = from;
- }
- runTo = to;
- return;
- }
- if (runFrom !== -1 && pos >= runFrom && pos <= runTo) {
- hit = { from: runFrom, to: runTo };
- }
- runFrom = -1;
- runTo = -1;
- });
- if (hit) {
- return hit;
- }
- if (runFrom !== -1 && pos >= runFrom && pos <= runTo) {
- return { from: runFrom, to: runTo };
- }
- return null;
-}
-
-export const HeadingMarks = Extension.create({
- name: "headingMarks",
- addProseMirrorPlugins() {
- return [
- new Plugin({
- key: new PluginKey("headingMarks"),
- props: {
- decorations(state) {
- const { $from } = state.selection;
- if ($from.parent.type.name === "codeBlock") {
- const lang = String($from.parent.attrs.language ?? "");
- return DecorationSet.create(state.doc, [
- Decoration.node($from.before(), $from.after(), {
- class: "is-editing",
- "data-fence-open": fenceOpenText(lang),
- }),
- ]);
- }
- if ($from.parent.type.name === "heading") {
- const level = Number($from.parent.attrs.level ?? 1);
- return DecorationSet.create(state.doc, [
- Decoration.node($from.before(), $from.after(), {
- class: "is-editing",
- "data-heading-marks": headingMarkText(level),
- }),
- ]);
- }
- const range = findInlineCodeRange(state.doc, $from.pos);
- if (!range) {
- return DecorationSet.empty;
- }
- return DecorationSet.create(state.doc, [
- Decoration.inline(range.from, range.to, { class: "is-editing-ticks" }),
- ]);
- },
- },
- }),
- ];
- },
-});
diff --git a/src/lib/editor/tableControls.ts b/src/lib/editor/tableControls.ts
index 89c92ad..61aa363 100644
--- a/src/lib/editor/tableControls.ts
+++ b/src/lib/editor/tableControls.ts
@@ -220,19 +220,40 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
// Native cursor movement can precede ProseMirror's selectionchange
// observer (especially during key repeat). Test the visible caret.
const native = document.getSelection();
- if (native?.anchorNode && native.focusNode && _editorView.dom.contains(native.anchorNode) && _editorView.dom.contains(native.focusNode)) {
+ const readNative = (scroll = false) => {
+ if (!native?.anchorNode || !native.focusNode || !_editorView.dom.contains(native.anchorNode) || !_editorView.dom.contains(native.focusNode)) return;
const anchor = _editorView.posAtDOM(native.anchorNode, native.anchorOffset);
const head = _editorView.posAtDOM(native.focusNode, native.focusOffset);
- if (anchor !== _editorView.state.selection.anchor || head !== _editorView.state.selection.head) editor!.commands.setTextSelection({ from: anchor, to: head });
- }
- if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey || !_editorView.state.selection.empty) return false;
+ if (anchor === _editorView.state.selection.anchor && head === _editorView.state.selection.head) return;
+ const chain = editor!.chain().setTextSelection({ from: anchor, to: head });
+ (scroll ? chain.scrollIntoView() : chain).run();
+ };
+ readNative();
+ // ProseMirror reads a native move on the next selectionchange. Its
+ // delayed focus check can run first and restore the old selection,
+ // so the move is lost under load. Move the DOM selection here and
+ // read the result at once. Other shortcuts stay with the browser.
+ const mac = navigator.platform.includes("Mac");
+ const vertical = event.key === "ArrowUp" || event.key === "ArrowDown";
+ const word = mac ? event.altKey : event.ctrlKey;
+ const moveNative = () => {
+ if (!native || event.metaKey || (mac ? event.ctrlKey : event.altKey) || (vertical && word)) return false;
+ native.modify(
+ event.shiftKey ? "extend" : "move",
+ vertical ? (event.key === "ArrowUp" ? "backward" : "forward") : event.key === "ArrowLeft" ? "left" : "right",
+ vertical ? "line" : word ? "word" : "character",
+ );
+ readNative(true);
+ return true;
+ };
+ if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey || !_editorView.state.selection.empty) return moveNative();
const direction = event.key === "ArrowLeft" ? "left" : event.key === "ArrowRight" ? "right" : event.key === "ArrowUp" ? "up" : "down";
const horizontal = direction === "left" || direction === "right";
const backwards = direction === "left" || direction === "up";
const { $head } = _editorView.state.selection;
// Pasted rich text can have several paragraphs within one cell.
- if ($head.depth && (backwards ? $head.before(1) > 0 : $head.after(1) < _editorView.state.doc.content.size)) return false;
- if (!_editorView.endOfTextblock(direction)) return false;
+ if ($head.depth && (backwards ? $head.before(1) > 0 : $head.after(1) < _editorView.state.doc.content.size)) return moveNative();
+ if (!_editorView.endOfTextblock(direction)) return moveNative();
event.preventDefault();
const cells = [...table!.querySelectorAll("th, td")];
const next = horizontal
diff --git a/src/lib/editor/writerMarks.ts b/src/lib/editor/writerMarks.ts
deleted file mode 100644
index eb32c56..0000000
--- a/src/lib/editor/writerMarks.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Mark } from "@tiptap/core";
-
-export const MathMark = Mark.create({
- name: "math",
- parseHTML() {
- return [{ tag: "span[data-math]" }];
- },
- renderHTML() {
- return ["span", { "data-math": "1", class: "md-math" }, 0];
- },
-});
-
-export const CommentMark = Mark.create({
- name: "comment",
- parseHTML() {
- return [{ tag: "span[data-comment]" }];
- },
- renderHTML() {
- return ["span", { "data-comment": "1", class: "md-comment" }, 0];
- },
-});
diff --git a/src/lib/editor/writerMenu.ts b/src/lib/editor/writerMenu.ts
deleted file mode 100644
index 6808308..0000000
--- a/src/lib/editor/writerMenu.ts
+++ /dev/null
@@ -1,144 +0,0 @@
-import { tr } from '../i18n/index.ts';
-import type { Editor } from "@tiptap/core";
-import type { MenuItem } from "../layout/menuTypes";
-
-function selectedText(editor: Editor): string {
- const { from, to } = editor.state.selection;
- return editor.state.doc.textBetween(from, to, "\n");
-}
-
-async function writeClipboard(text: string): Promise {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- return false;
- }
-}
-
-export async function cutSelection(editor: Editor): Promise {
- const text = selectedText(editor);
- if (text && !(await writeClipboard(text))) {
- return;
- }
- editor.chain().focus().deleteSelection().run();
-}
-
-export async function copySelection(editor: Editor): Promise {
- const text = selectedText(editor);
- if (text) {
- await writeClipboard(text);
- }
-}
-
-export async function pasteClipboard(editor: Editor): Promise {
- let text = "";
- try {
- text = await navigator.clipboard.readText();
- } catch {
- return;
- }
- if (!text) {
- return;
- }
- editor.chain().focus().run();
- editor.view.dispatch(editor.state.tr.insertText(text));
-}
-
-export function writerContextItems(editor: Editor): MenuItem[] {
- const inTable = editor.isActive("table");
- return [
- { kind: "action", label: tr("Cut"), run: () => void cutSelection(editor) },
- { kind: "action", label: tr("Copy"), run: () => void copySelection(editor) },
- { kind: "action", label: tr("Paste"), run: () => void pasteClipboard(editor) },
- { kind: "sep" },
- {
- kind: "group",
- label: tr("Style"),
- items: [
- { kind: "action", label: tr("Heading {level}", { level: 1 }), run: () => editor.chain().focus().toggleHeading({ level: 1 }).run() },
- { kind: "action", label: tr("Heading {level}", { level: 2 }), run: () => editor.chain().focus().toggleHeading({ level: 2 }).run() },
- { kind: "action", label: tr("Heading {level}", { level: 3 }), run: () => editor.chain().focus().toggleHeading({ level: 3 }).run() },
- { kind: "action", label: tr("Heading {level}", { level: 4 }), run: () => editor.chain().focus().toggleHeading({ level: 4 }).run() },
- { kind: "action", label: tr("Heading {level}", { level: 5 }), run: () => editor.chain().focus().toggleHeading({ level: 5 }).run() },
- { kind: "action", label: tr("Heading {level}", { level: 6 }), run: () => editor.chain().focus().toggleHeading({ level: 6 }).run() },
- { kind: "action", label: tr("Body"), run: () => editor.chain().focus().setParagraph().run() },
- { kind: "action", label: tr("Quote"), run: () => editor.chain().focus().toggleBlockquote().run() },
- { kind: "sep" },
- { kind: "action", label: tr("Bullet list"), run: () => editor.chain().focus().toggleBulletList().run() },
- { kind: "action", label: tr("Numbered list"), run: () => editor.chain().focus().toggleOrderedList().run() },
- { kind: "action", label: tr("Task list"), run: () => editor.chain().focus().toggleTaskList().run() },
- ],
- },
- {
- kind: "group",
- label: tr("Format"),
- items: [
- { kind: "action", label: tr("Bold"), run: () => editor.chain().focus().toggleBold().run() },
- { kind: "action", label: tr("Italic"), run: () => editor.chain().focus().toggleItalic().run() },
- { kind: "action", label: tr("Strikethrough"), run: () => editor.chain().focus().toggleStrike().run() },
- { kind: "action", label: tr("Highlight"), run: () => editor.chain().focus().toggleHighlight().run() },
- { kind: "action", label: tr("Code"), run: () => editor.chain().focus().toggleCode().run() },
- { kind: "action", label: tr("Math"), run: () => editor.chain().focus().toggleMark("math").run() },
- { kind: "action", label: tr("Comment"), run: () => editor.chain().focus().toggleMark("comment").run() },
- { kind: "sep" },
- { kind: "action", label: tr("Clear formatting"), run: () => editor.chain().focus().unsetAllMarks().run() },
- ],
- },
- {
- kind: "group",
- label: tr("Table"),
- items: [
- {
- kind: "action",
- label: tr("Insert table"),
- run: () => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
- },
- { kind: "sep" },
- {
- kind: "action",
- label: tr("Add row above"),
- disabled: !inTable,
- run: () => editor.chain().focus().addRowBefore().run(),
- },
- {
- kind: "action",
- label: tr("Add row below"),
- disabled: !inTable,
- run: () => editor.chain().focus().addRowAfter().run(),
- },
- {
- kind: "action",
- label: tr("Delete row"),
- disabled: !inTable,
- run: () => editor.chain().focus().deleteRow().run(),
- },
- { kind: "sep" },
- {
- kind: "action",
- label: tr("Add column left"),
- disabled: !inTable,
- run: () => editor.chain().focus().addColumnBefore().run(),
- },
- {
- kind: "action",
- label: tr("Add column right"),
- disabled: !inTable,
- run: () => editor.chain().focus().addColumnAfter().run(),
- },
- {
- kind: "action",
- label: tr("Delete column"),
- disabled: !inTable,
- run: () => editor.chain().focus().deleteColumn().run(),
- },
- {
- kind: "action",
- label: tr("Delete table"),
- disabled: !inTable,
- run: () => editor.chain().focus().deleteTable().run(),
- },
- ],
- },
- ];
-}
diff --git a/src/lib/layout/Workbench.svelte b/src/lib/layout/Workbench.svelte
index f7dd9a7..4e02512 100644
--- a/src/lib/layout/Workbench.svelte
+++ b/src/lib/layout/Workbench.svelte
@@ -1206,7 +1206,7 @@
let refreshTimer: ReturnType;
const register = (off: () => void) => { if (disposed) off(); else unlisteners.push(off); };
void onWorkspaceEvent((event) => {
- if (event.root !== workspace?.root || event.kind === "access") return;
+ if (event.root !== workspace?.root) return;
if (event.paths.every(path => path.startsWith(".runestone/") || path.split("/").pop()?.startsWith(".runestone-save-"))) return;
clearTimeout(refreshTimer);
refreshTimer = setTimeout(() => {
diff --git a/tests/tsconfig.json b/tests/tsconfig.json
index c0825df..84bd7d2 100644
--- a/tests/tsconfig.json
+++ b/tests/tsconfig.json
@@ -2,8 +2,8 @@
// Type checks for the unit tests. They run in Node with --experimental-strip-types.
"extends": "../tsconfig.json",
"compilerOptions": {
- // The TipTap packages declare the editor commands that src/lib/editor/writerMenu.ts uses.
- "types": ["node", "@tiptap/starter-kit", "@tiptap/extension-highlight", "@tiptap/extension-table", "@tiptap/extension-task-list"],
+ // The TipTap packages declare the editor commands that the table cell editor uses.
+ "types": ["node", "@tiptap/starter-kit", "@tiptap/extension-highlight"],
"checkJs": false
},
"include": ["unit/**/*.ts", "../src/**/*.d.ts"],
diff --git a/tests/unit/editor/headingMarks.spec.ts b/tests/unit/editor/headingMarks.spec.ts
deleted file mode 100644
index 091e613..0000000
--- a/tests/unit/editor/headingMarks.spec.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import assert from "node:assert/strict";
-import test from "node:test";
-import { fenceOpenText, headingMarkText } from "../../../src/lib/editor/headingMarks.ts";
-
-test("heading marks match the heading level", () => {
- assert.equal(headingMarkText(1), "#");
- assert.equal(headingMarkText(3), "###");
- assert.equal(headingMarkText(6), "######");
-});
-
-test("fence open marks include the language", () => {
- assert.equal(fenceOpenText(""), "```");
- assert.equal(fenceOpenText("js"), "```js");
- assert.equal(fenceOpenText(" pp "), "```pp");
-});
diff --git a/tests/unit/editor/writerMenu.spec.ts b/tests/unit/editor/writerMenu.spec.ts
deleted file mode 100644
index 57be724..0000000
--- a/tests/unit/editor/writerMenu.spec.ts
+++ /dev/null
@@ -1,244 +0,0 @@
-import assert from "node:assert/strict";
-import test from "node:test";
-import {
- copySelection,
- cutSelection,
- pasteClipboard,
- writerContextItems,
-} from "../../../src/lib/editor/writerMenu.ts";
-
-type Harness = {
- selected: string;
- inTable: boolean;
- deleted: boolean;
- focused: boolean;
- inserted: string | null;
- dispatched: boolean;
-};
-
-function fakeEditor(init?: { selected?: string; inTable?: boolean }) {
- const harness: Harness = {
- selected: init?.selected ?? "",
- inTable: init?.inTable ?? false,
- deleted: false,
- focused: false,
- inserted: null,
- dispatched: false,
- };
- const tr = {
- insertText(text: string) {
- harness.inserted = text;
- return tr;
- },
- };
- const chainApi = {
- focus() {
- harness.focused = true;
- return chainApi;
- },
- deleteSelection() {
- harness.deleted = true;
- return chainApi;
- },
- run() {
- return true;
- },
- };
- const editor = {
- isActive(name: string) {
- return name === "table" && harness.inTable;
- },
- chain() {
- return chainApi;
- },
- state: {
- selection: { from: 0, to: harness.selected.length },
- doc: {
- textBetween() {
- return harness.selected;
- },
- },
- tr,
- },
- view: {
- dispatch() {
- harness.dispatched = true;
- },
- },
- };
- return { editor, harness };
-}
-
-function withClipboard(
- impl: { writeText?: (text: string) => Promise; readText?: () => Promise },
- run: () => Promise,
-): Promise {
- const previous = Object.getOwnPropertyDescriptor(globalThis, "navigator");
- Object.defineProperty(globalThis, "navigator", {
- configurable: true,
- value: { clipboard: impl },
- });
- return run().finally(() => {
- if (previous) {
- Object.defineProperty(globalThis, "navigator", previous);
- } else {
- Reflect.deleteProperty(globalThis, "navigator");
- }
- });
-}
-
-function actionLabels(items: ReturnType): string[] {
- const labels: string[] = [];
- for (const item of items) {
- if (item.kind === "action") {
- labels.push(item.label);
- } else if (item.kind === "group") {
- for (const sub of item.items) {
- if (sub.kind === "action") {
- labels.push(sub.label);
- }
- }
- }
- }
- return labels;
-}
-
-test("paste inserts clipboard text without parsing tags", async () => {
- const { editor, harness } = fakeEditor();
- await withClipboard(
- { readText: async () => "bold" },
- async () => {
- await pasteClipboard(editor as never);
- },
- );
- assert.equal(harness.focused, true);
- assert.equal(harness.dispatched, true);
- assert.equal(harness.inserted, "bold");
-});
-
-test("paste swallows clipboard errors", async () => {
- const { editor, harness } = fakeEditor();
- await withClipboard(
- {
- readText: async () => {
- throw new Error("denied");
- },
- },
- async () => {
- await pasteClipboard(editor as never);
- },
- );
- assert.equal(harness.dispatched, false);
- assert.equal(harness.inserted, null);
-});
-
-test("cut keeps the selection when clipboard write fails", async () => {
- const { editor, harness } = fakeEditor({ selected: "gone" });
- await withClipboard(
- {
- writeText: async () => {
- throw new Error("denied");
- },
- },
- async () => {
- await cutSelection(editor as never);
- },
- );
- assert.equal(harness.deleted, false);
-});
-
-test("copy swallows clipboard errors", async () => {
- const { editor } = fakeEditor({ selected: "keep" });
- let attempted = false;
- await withClipboard(
- {
- writeText: async () => {
- attempted = true;
- throw new Error("denied");
- },
- },
- async () => {
- await copySelection(editor as never);
- },
- );
- assert.equal(attempted, true);
-});
-
-test("cut writes selected text then deletes it", async () => {
- const { editor, harness } = fakeEditor({ selected: "clip" });
- let written = "";
- await withClipboard(
- {
- writeText: async (text) => {
- written = text;
- },
- },
- async () => {
- await cutSelection(editor as never);
- },
- );
- assert.equal(written, "clip");
- assert.equal(harness.deleted, true);
-});
-
-test("table row and column actions disable outside a table", () => {
- const { editor } = fakeEditor({ inTable: false });
- const items = writerContextItems(editor as never);
- const table = items.find((item) => item.kind === "group" && item.label === "Table");
- assert.equal(table?.kind, "group");
- if (table?.kind !== "group") {
- return;
- }
- const byLabel = new Map(
- table.items.filter((item) => item.kind === "action").map((item) => [item.label, item]),
- );
- assert.equal(byLabel.get("Insert table")?.disabled, undefined);
- assert.equal(byLabel.get("Add row above")?.disabled, true);
- assert.equal(byLabel.get("Delete table")?.disabled, true);
-});
-
-test("table row and column actions enable inside a table", () => {
- const { editor } = fakeEditor({ inTable: true });
- const items = writerContextItems(editor as never);
- const table = items.find((item) => item.kind === "group" && item.label === "Table");
- assert.equal(table?.kind, "group");
- if (table?.kind !== "group") {
- return;
- }
- const byLabel = new Map(
- table.items.filter((item) => item.kind === "action").map((item) => [item.label, item]),
- );
- assert.equal(byLabel.get("Insert table")?.disabled, undefined);
- assert.equal(byLabel.get("Add row above")?.disabled, false);
- assert.equal(byLabel.get("Delete table")?.disabled, false);
-});
-
-test("style and format actions cover the requested commands", () => {
- const { editor } = fakeEditor();
- const labels = actionLabels(writerContextItems(editor as never));
- for (const label of [
- "Cut",
- "Copy",
- "Paste",
- "Heading 1",
- "Heading 6",
- "Body",
- "Quote",
- "Bullet list",
- "Numbered list",
- "Task list",
- "Bold",
- "Italic",
- "Strikethrough",
- "Highlight",
- "Code",
- "Math",
- "Comment",
- "Clear formatting",
- "Insert table",
- ]) {
- assert.equal(labels.includes(label), true, label);
- }
- assert.equal(labels.includes("Superscript"), false);
- assert.equal(labels.includes("Subscript"), false);
-});