Add interface languages and improve themes and workspace controls for 0.1.36

This commit is contained in:
Knotty Wyvern
2026-10-15 10:55:59 -07:00
parent b066359b66
commit 68e86ab6eb
98 changed files with 5499 additions and 874 deletions
+25 -24
View File
@@ -1,3 +1,4 @@
import { tr } from "../i18n/index.ts";
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
import { invoke, isTauri } from "@tauri-apps/api/core";
import { wordAt } from "./spellingWord";
@@ -89,40 +90,40 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
editor.select(selectedLink.targetFrom, selectedLink.targetTo); editor.focus();
}), { separator: true as const }] : []),
...(editor.undo ? [
{ label: "Undo", icon: "undo" as const, shortcut: "Ctrl+Z", disabled: !editor.canUndo?.(), run: () => { close(); editor.undo?.(); } },
{ label: "Redo", icon: "redo" as const, shortcut: "Ctrl+Shift+Z", disabled: !editor.canRedo?.(), run: () => { close(); editor.redo?.(); } },
{ label: tr("Undo"), icon: "undo" as const, shortcut: "Ctrl+Z", disabled: !editor.canUndo?.(), run: () => { close(); editor.undo?.(); } },
{ label: tr("Redo"), icon: "redo" as const, shortcut: "Ctrl+Shift+Z", disabled: !editor.canRedo?.(), run: () => { close(); editor.redo?.(); } },
{ separator: true as const },
] : []),
{ label: "Add link", icon: "link", run: () => link(false) },
{ label: "Add external link", icon: "external", run: () => link(true) },
{ label: tr("Add link"), icon: "link", run: () => link(false) },
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
{ separator: true },
{ label: text ? `Search for “${text.length > 32 ? text.slice(0, 32) + "…" : text}”` : "Search selection", icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
{ label: "Extract current selection…", icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
{ 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); } },
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
const target = await actions.onExtract?.(text, text, valid);
if (target) apply(replacement(selection, `[[${target}|${text.replace(/[\[\]|]/g, "").replace(/\s+/g, " ").trim()}]]`));
}) },
{ label: "Format", icon: "format", children: cellFormats.flatMap(([label, kind]) => [
{ label: tr("Format"), icon: "format", children: cellFormats.flatMap(([label, kind]) => [
...(kind === "code" || kind === "clear" ? [{ separator: true } as const] : []),
{ label, icon: kind, disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
{ label: tr(label), icon: kind, disabled: kind === "clear" && !text, run: () => apply(formatText(source, selection, kind)) },
]) },
{ label: "Paragraph", icon: "paragraph", children: [
paragraph("Bullet list", "bullet", "bullet"), paragraph("Numbered list", "number", "number"), paragraph("Task list", "task", "task"),
{ label: tr("Paragraph"), icon: "paragraph", children: [
paragraph(tr("Bullet list"), "bullet", "bullet"), paragraph(tr("Numbered list"), "number", "number"), paragraph(tr("Task list"), "task", "task"),
{ separator: true },
...([1, 2, 3, 4, 5, 6] as const).map(level => paragraph(`Heading ${level}`, level, "heading")),
paragraph("Body", "body", "paragraph"), { separator: true }, paragraph("Quote", "quote", "quote"),
...([1, 2, 3, 4, 5, 6] as const).map(level => paragraph(tr("Heading {level}", { level }), level, "heading")),
paragraph(tr("Body"), "body", "paragraph"), { separator: true }, paragraph(tr("Quote"), "quote", "quote"),
] },
{ label: "Insert", icon: "insert", children: [
insert("Footnote", "footnote", "footnote"), insert("Table", "table", "table"), insert("Callout", "callout", "quote"), insert("Horizontal rule", "rule", "rule"),
{ separator: true }, insert("Code block", "code", "code"), insert("Math block", "math", "math"),
{ label: tr("Insert"), icon: "insert", children: [
insert(tr("Footnote"), "footnote", "footnote"), insert(tr("Table"), "table", "table"), insert(tr("Callout"), "callout", "quote"), insert(tr("Horizontal rule"), "rule", "rule"),
{ separator: true }, insert(tr("Code block"), "code", "code"), insert(tr("Math block"), "math", "math"),
] },
{ separator: true },
{ label: "Cut", icon: "cut", disabled: !text, run: () => clipboard("cut") },
{ label: "Copy", icon: "copy", disabled: !text, run: () => clipboard("copy") },
{ label: "Paste", icon: "paste", run: () => clipboard("paste") },
{ label: "Paste as plain text", icon: "paste-text", run: () => clipboard("plain") },
{ label: "Select all", icon: "select", run: () => { close(); editor.selectAll(); } },
{ label: tr("Cut"), icon: "cut", disabled: !text, run: () => clipboard("cut") },
{ label: tr("Copy"), icon: "copy", disabled: !text, run: () => clipboard("copy") },
{ label: tr("Paste"), icon: "paste", run: () => clipboard("paste") },
{ label: tr("Paste as plain text"), icon: "paste-text", run: () => clipboard("plain") },
{ label: tr("Select all"), icon: "select", run: () => { close(); editor.selectAll(); } },
];
root = actionMenu(x, y, items, close, "Markdown text actions");
root = actionMenu(x, y, items, close, tr("Markdown text actions"));
const opened = root;
const word = spellingOffset === undefined ? null : wordAt(source, spellingOffset);
if (word && isTauri()) {
@@ -130,14 +131,14 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
void invoke<{ language: string; words: string[]; misspelled: boolean }>("spelling_suggestions", { word: word.word, languages }).then(result => {
if (!result.misspelled || root !== opened || !valid()) return;
const suggestions: ActionMenuItem[] = result.words.map(value => ({ label: value, run: () => apply(replacement(word, value)) }));
if (!suggestions.length) suggestions.push({ label: "No spelling suggestions", disabled: true });
suggestions.push({ label: "Add to dictionary", icon: "book", run: () => {
if (!suggestions.length) suggestions.push({ label: tr("No spelling suggestions"), disabled: true });
suggestions.push({ label: tr("Add to dictionary"), icon: "book", run: () => {
close();
void invoke("spelling_suggestions", { word: word.word, languages: [result.language], add: true }).catch(() => report("Could not add the word to the dictionary."));
} });
const focusedLabel = opened.contains(document.activeElement) ? document.activeElement?.querySelector(".action-label")?.textContent : undefined;
opened.remove();
root = actionMenu(x, y, [...suggestions, { separator: true }, ...items], close, "Markdown text actions");
root = actionMenu(x, y, [...suggestions, { separator: true }, ...items], close, tr("Markdown text actions"));
if (focusedLabel) [...root.querySelectorAll<HTMLButtonElement>(":scope > button")].find(button => button.querySelector(".action-label")?.textContent === focusedLabel)?.focus();
}).catch(() => { /* Editing actions remain available without spelling suggestions. */ });
}