Update editor, themes, menus, backgrounds, and release tooling

This commit is contained in:
Knotty Wyvern
2026-10-14 16:19:51 -07:00
parent f6eaa52949
commit edef2520af
113 changed files with 5722 additions and 386 deletions
+241 -59
View File
@@ -6,7 +6,12 @@
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, findPluginEditor } from "$lib/plugins/external";
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
import { pluginSidebar, closePluginSidebar, pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginFileOpen, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external";
import { onMount, tick, untrack } from "svelte";
import { onMount, onDestroy, tick, untrack } from "svelte";
import type { MenuLink } from "$lib/editor/linkMenu";
import { loadMarks, saveMarks } from "$lib/workspace/marks";
import { moveMarks } from "$lib/workspace/treeMoveHistory";
import { retainEditorSessions } from "$lib/editor/sessions";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane } from "$lib/workspace/documentPanes";
import { selectedEditorText } from "$lib/editor/selection";
import { pluginHost } from "$lib/plugins/registry";
import type { Contributions } from "$lib/plugins/contracts";
@@ -41,6 +46,8 @@
import {
onWorkspaceEvent,
workspaceNew,
workspaceList,
workspaceOpenDefault,
workspaceCreate,
workspaceAbsPath,
workspaceLastPath,
@@ -93,7 +100,8 @@
let rightOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.rightOpen);
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
let terminalOpen = $state(false);
let reading = $state(false);
let documentPanes = $state(initialDocumentPanes());
const reading = $derived(documentPanes.panes.find(pane => pane.id === documentPanes.active)?.reading ?? false);
let quickOpen = $state(false);
let templateManager = $state(false);
let terminalStarted = $state(false);
@@ -136,11 +144,14 @@
let switching = false;
let workbenchReady = $state(false);
let documents: Documents | null = null;
let editorPane: EditorPane | undefined = $state();
let paneComponents = $state<Record<string, EditorPane | undefined>>({});
function activeEditor() { return paneComponents[documentPanes.active]; }
let fileTree: FileTree | undefined = $state();
let closingTabs = false;
const hasDirty = $derived(tabs.some(tab => tab.contents !== tab.saved));
function createDocuments() {
documentPanes = initialDocumentPanes();
const next = new Documents({
read: workspaceRead, write: workspaceWrite, image: workspaceReadDataUrl,
kind: path => isImagePath(path) ? "image" : "text", chrome: detectChrome,
@@ -149,10 +160,50 @@
tabs = next.buffers.map(tab => ({ ...tab }));
activePath = next.activePath;
const selected = next.active;
documentPanes = syncDocumentPanes(documentPanes, next.buffers.map(tab => tab.id), selected?.id ?? null);
if (selected) view = selected.chromeOverride ?? selected.chrome;
});
return next;
}
$effect(() => retainEditorSessions(tabs.map(tab => tab.id)));
onDestroy(() => retainEditorSessions([]));
const documentViews = $derived.by(() => {
const bounds = paneBounds(documentPanes.layout);
return documentPanes.panes.map(pane => ({ ...pane, buffer: tabs.find(tab => tab.id === pane.documentId) ?? null, bounds: bounds[pane.id] }))
.sort((a, b) => a.bounds.left - b.bounds.left);
});
function setReading(next: boolean, paneId = documentPanes.active) {
documentPanes = readDocumentPane(documentPanes, paneId, next);
}
function focusDocumentPane(paneId: string, focusEditor = false) {
const pane = documentPanes.panes.find(pane => pane.id === paneId);
if (!pane) return;
const tab = tabs.find(tab => tab.id === pane.documentId);
documentPanes = selectPane(documentPanes, paneId);
pluginEditorActive.set(false);
if (tab && documents?.active?.id !== tab.id) { focusLine = null; documents?.select(tab.relPath); }
if (focusEditor) void tick().then(() => {
if (documentPanes.active !== paneId) return;
paneComponents[paneId]?.focusEditor();
document.querySelector<HTMLElement>(`[data-document-pane="${paneId}"]`)?.scrollIntoView({ block: "nearest", inline: "nearest" });
});
}
function closeSplit(paneId: string) {
documentPanes = closeDocumentPane(documentPanes, paneId);
focusDocumentPane(documentPanes.active, true);
}
async function openToRight(file: TreeEntry, sourcePane: string) {
const current = documents;
const source = documentPanes.panes.find(pane => pane.id === sourcePane);
if (!current || switching || !source) return;
await current.open(file, "background");
if (documents !== current || switching || documentPanes.active !== sourcePane
|| documentPanes.panes.find(pane => pane.id === sourcePane)?.documentId !== source.documentId) return;
const target = current.buffers.find(tab => tab.relPath === file.rel_path);
if (!target) return;
documentPanes = splitDocumentPane(documentPanes, sourcePane, target.id, crypto.randomUUID());
focusDocumentPane(documentPanes.active, true);
}
let focusLine = $state<number | null>(null);
let dragging = $state<"left" | "right" | "bottom" | null>(null);
let centerStack: HTMLElement | undefined = $state();
@@ -212,7 +263,7 @@
function toggleChrome() {
const next = view === "Writing" ? "Ide" : "Writing";
reading = false;
setReading(false);
applyChrome(next);
documents?.setChrome(next);
}
@@ -306,7 +357,7 @@
await new Promise(resolve => setTimeout(resolve, 100));
}
} else throw new Error("Invalid tab transfer.");
reading = transfer.reading === true;
setReading(transfer.reading === true);
localStorage.setItem(key + ".accepted", "true");
localStorage.removeItem(key);
}
@@ -322,6 +373,7 @@
pluginEditorActive.set(false);
focusLine = null;
documents?.select(relPath);
focusDocumentPane(documentPanes.active, true);
status = documents?.active?.kind === "empty" ? "New tab" : relPath;
}
@@ -353,7 +405,7 @@
if (actions.some(action => "label" in action && /(?:move|open).*new window/i.test(action.label))) return actions;
return tab ? [{ label: "Open in new window", icon: "external", disabled: !desktop || !workspace, run: () => { void detachTab(tab); } }, ...actions] : [];
}
async function detachTab(item: WorkbenchTab) {
async function detachTab(item: WorkbenchTab, keepSource = false) {
const tab = workingTabs.find(tab => tab.id === item.id);
if (!tab || !workspace || !desktop) return;
if ("plugin" in tab) {
@@ -373,9 +425,9 @@
};
const accepted = (event: StorageEvent) => {
if (event.key !== key + ".accepted" || event.newValue !== "true") return;
if ("buffer" in tab) {
if (!keepSource && "buffer" in tab) {
if (documents === current && bufferSnapshot(current?.buffers.find(buffer => buffer.id === tab.buffer.id)) === snapshot) current?.close(tab.relPath);
} else if (JSON.stringify(pluginTabState(tab.plugin)) === snapshot) closePluginEditor(tab.plugin.key);
} else if (!keepSource && "plugin" in tab && JSON.stringify(pluginTabState(tab.plugin)) === snapshot) closePluginEditor(tab.plugin.key);
finish();
};
try {
@@ -449,7 +501,7 @@
if (tab.kind === "text" && isMarkdownPath(tab.relPath)) {
items.push(
{ label: "Save as template", icon: "copy", run: () => { void saveTemplate({ name: tab.name, rel_path: tab.relPath, kind: "file" }); } },
{ label: reading ? "Editing view" : "Reading view", icon: "book", run: () => editorPane?.toggleReadingView() },
{ label: reading ? "Editing view" : "Reading view", icon: "book", run: () => activeEditor()?.toggleReadingView() },
{ label: isIde ? "Writing mode" : "Source mode", icon: "code", run: toggleChrome },
);
}
@@ -482,7 +534,7 @@
error = null;
focusLine = null;
if (line) {
reading = false;
setReading(false);
queueMicrotask(() => { focusLine = line; });
}
} catch (err) { if (documents === current) error = String(err); }
@@ -492,8 +544,8 @@
const current = documents;
await openFile(entry);
if (documents !== current || current?.active?.relPath !== entry.rel_path || !isMarkdownPath(entry.rel_path)) return;
reading = false;
editorPane?.focusTitle(current.active.id);
setReading(false);
activeEditor()?.focusTitle(current.active.id);
}
function readFileDataUrl(file: File): Promise<string> {
@@ -505,11 +557,11 @@
});
}
async function insertImage(file: File): Promise<string | null> {
if (!buffer || buffer.kind !== "text" || !isMarkdownPath(buffer.relPath)) {
async function insertImage(file: File, note = buffer): Promise<string | null> {
if (!note || note.kind !== "text" || !isMarkdownPath(note.relPath)) {
return null;
}
const noteRel = buffer.relPath;
const noteRel = note.relPath;
const current = documents;
try {
const rel = attachmentRel(file.name);
@@ -538,8 +590,8 @@
searchRequest = { text, id: (searchRequest?.id || 0) + 1 };
}
async function extractSelection(markdown: string, label: string, valid: () => boolean): Promise<string | null> {
const current = documents, note = buffer;
async function extractSelection(markdown: string, label: string, valid: () => boolean, note = buffer): Promise<string | null> {
const current = documents;
if (!workspace || !current || !note) return null;
const folder = note.relPath.slice(0, note.relPath.lastIndexOf("/") + 1);
const suggested = label.replace(/[<>:"/\\|?*\r\n]/g, " ").trim().slice(0, 60) || "Extracted selection";
@@ -587,8 +639,7 @@
} finally { saving = false; }
}
async function saveCopy() {
const tab = buffer;
async function saveCopy(tab = buffer) {
if (!tab || tab.kind !== "text") return;
const name = await requestText("Save a copy as (workspace relative path)", tab.relPath.replace(/(\.[^./]+)?$/, " copy$1"));
if (!name) return;
@@ -789,7 +840,72 @@
}
}
async function openLink(kind: "md" | "wiki", target: string) {
function workspaceLinkItems(link: MenuLink, origin = activePath ?? "", sourcePane = documentPanes.active): ActionMenuItem[] {
const current = documents, currentWorkspace = workspace;
const valid = () => documents === current && workspace === currentWorkspace && !!currentWorkspace;
const entry = async () => {
for (const path of linkCandidates(origin, link.target, link.kind)) {
if (!valid()) throw new Error("The workspace changed. Open the link menu again.");
const parent = path.split("/").slice(0, -1).join("/");
let files: TreeEntry[];
try { files = await workspaceList(parent); } catch { continue; }
const found = files.find(file => file.rel_path === path && file.kind === "file");
if (found) return found;
}
throw new Error(`Could not find ${link.target} in the workspace.`);
};
const run = (action: (file: TreeEntry) => void | Promise<void>) => () => {
void entry().then(file => { if (valid()) return action(file); }).catch(reason => { error = String(reason); });
};
async function rename(file: TreeEntry, move = false) {
const typed = await requestText(move ? "Move file to (workspace path, including filename)" : "New file name", move ? file.rel_path : file.name);
if (!typed || !valid()) return;
let to = typed.trim().replaceAll("\\", "/");
if (move) {
if (!to || to.startsWith("/") || to.split("/").some(part => !part || part === "." || part === "..") || /[<>:"|?*\u0000-\u001f]/.test(to)) throw new Error("Enter a relative workspace path without reserved characters.");
} else {
const plan = planRename(file.rel_path, to);
if (plan.action === "noop") return;
if (plan.action === "error") throw new Error(plan.message);
to = plan.to;
}
if (to === file.rel_path) return;
const marks = await loadMarks();
if (!valid()) return;
await workspaceRename(file.rel_path, to, currentWorkspace!.root);
if (!valid()) return;
applyPathRename(file.rel_path, to);
await saveMarks(moveMarks(marks, file.rel_path, to));
refreshToken++;
status = `Moved to ${to}`;
}
return [
{ label: "Open to the right", icon: "split-right", run: run(file => openToRight(file, sourcePane)) },
{ label: "Open in new window", icon: "external", disabled: !desktop, run: run(async file => {
await openFile(file, undefined, "new");
if (!valid()) return;
const tab = workingTabs.find(tab => tab.relPath === file.rel_path);
if (tab) await detachTab(tab, true);
}) },
{ label: "Copy path", icon: "copy", children: [
{ label: "Workspace path", icon: "copy", run: run(file => copyTabPath(file.rel_path, false)) },
{ label: "System path", icon: "copy", run: run(file => copyTabPath(file.rel_path, true)) },
] },
{ label: "Rename…", icon: "rename", run: run(file => rename(file)) },
{ label: "Move file to…", icon: "folder", run: run(file => rename(file, true)) },
{ label: "Bookmark", icon: "bookmark", run: run(async file => {
const marks = await loadMarks();
if (!valid()) return;
if (!marks.bookmarks.includes(file.rel_path)) await saveMarks({ ...marks, bookmarks: [...marks.bookmarks, file.rel_path] });
refreshToken++; status = `Bookmarked ${file.name}`;
}) },
{ label: "Open in default app", icon: "external", run: run(file => workspaceOpenDefault(file.rel_path)) },
{ label: "Show in system explorer", icon: "folder", run: run(file => workspaceReveal(file.rel_path)) },
{ label: "Reveal file in navigation", icon: "folder", run: run(async file => { closePluginSidebar(); leftView = "files"; leftOpen = true; await tick(); await fileTree?.revealPath(file.rel_path); }) },
];
}
async function openLink(kind: "md" | "wiki", target: string, origin = activePath ?? "", paneId = documentPanes.active) {
if (/^(https?:\/\/|mailto:)/i.test(target)) {
try {
if (/^https?:\/\//i.test(target) && await pluginHost.get("browser")?.open(target)) return;
@@ -797,7 +913,8 @@
} catch (err) { error = String(err); }
return;
}
const rels = linkCandidates(activePath ?? "", target, kind);
const rels = linkCandidates(origin, target, kind);
focusDocumentPane(paneId);
for (const rel of rels) {
try {
await documents?.open({ name: rel.split("/").pop() ?? rel, rel_path: rel, kind: "file" });
@@ -952,6 +1069,7 @@
onpointerup={() => (dragging = null)}
onpointerleave={() => (dragging = null)}
>
<div class="workarea-background" aria-hidden="true"></div>
<header class="header" data-tauri-drag-region>
<div class="header-left" data-tauri-drag-region>
{#if !transferredWindow}
@@ -1034,6 +1152,7 @@
<div class="left-stack">
<div class="left-layer" class:shown={leftView === "files"}>
<FileTree
bind:this={fileTree}
workspaceRoot={workspace.root}
showInternal={settings.showInternalFolder}
onSaveTemplate={(entry) => { void saveTemplate(entry); }}
@@ -1103,39 +1222,57 @@
{/each}
</div>
<div class="editor-host" class:plugin-covered={editorPluginVisible}>
{#if buffer?.diskError}
<div class="conflict" role="alert"><span>{buffer.diskError}</span><button onclick={() => void saveCopy()}>Save a copy</button><button onclick={() => void documents?.refresh()}>Retry</button></div>
{:else if buffer?.diskContents != null}
<div class="conflict" role="alert">
<span>This file changed on disk. Your edits are preserved. Review both versions before saving.</span>
<button onclick={() => { if (buffer) documents?.resolve(buffer.id, true); }}>Use disk version</button>
<button onclick={() => { if (buffer) documents?.resolve(buffer.id, false); }}>Keep my edits</button>
<button onclick={() => void saveCopy()}>Save a copy</button>
</div>
<details class="disk-review"><summary>View disk version</summary><pre>{buffer.diskContents}</pre></details>
{/if}
<EditorPane
bind:this={editorPane}
{tabs}
hasWorkspace={!!workspace}
onOpenWorkspace={() => void chooseWorkspace()}
onNewFile={() => void newFile()}
onNewNote={(event) => { void newNote(event); }}
onQuickOpen={() => quickOpen = true}
onOpenBrowser={browserContribution?.newTab ? () => void openBrowser() : undefined}
{browserOpening}
{buffer}
chrome={view}
{reading}
{focusLine}
{onChange}
onInsertImage={insertImage}
onRenameTitle={renameNoteTitle}
tableActions={{ onSearch: searchSelection, onExtract: extractSelection }}
onToggleReading={() => (reading = !reading)}
onToggleChrome={toggleChrome}
onOpenLink={(kind, target) => void openLink(kind, target)}
/>
<div class="document-panes" class:split={documentViews.length > 1}>
{#each documentViews as pane (pane.id)}
<!-- svelte-ignore a11y_no_static_element_interactions (Focus identifies the document for shared commands.) -->
<div class="document-pane" class:focused={documentPanes.active === pane.id}
data-document-pane={pane.id} data-document-path={pane.buffer?.relPath ?? ""}
style:--pane-weight={pane.bounds.width}
onpointerdowncapture={() => focusDocumentPane(pane.id)}
onfocusin={() => focusDocumentPane(pane.id)}>
{#if pane.buffer?.diskError}
<div class="conflict" role="alert"><span>{pane.buffer.diskError}</span><button onclick={() => void saveCopy(pane.buffer)}>Save a copy</button><button onclick={() => void documents?.refresh()}>Retry</button></div>
{:else if pane.buffer?.diskContents != null}
<div class="conflict" role="alert">
<span>This file changed on disk. Your edits are preserved. Review both versions before saving.</span>
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, true); }}>Use disk version</button>
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, false); }}>Keep my edits</button>
<button onclick={() => void saveCopy(pane.buffer)}>Save a copy</button>
</div>
<details class="disk-review"><summary>View disk version</summary><pre>{pane.buffer.diskContents}</pre></details>
{/if}
<EditorPane
bind:this={paneComponents[pane.id]}
{tabs}
active={documentPanes.active === pane.id}
onCloseSplit={documentViews.length > 1 ? () => closeSplit(pane.id) : undefined}
hasWorkspace={!!workspace}
onOpenWorkspace={() => void chooseWorkspace()}
onNewFile={() => void newFile()}
onNewNote={(event) => { void newNote(event); }}
onQuickOpen={() => quickOpen = true}
onOpenBrowser={browserContribution?.newTab ? () => void openBrowser() : undefined}
{browserOpening}
buffer={pane.buffer}
chrome={pane.buffer?.chromeOverride ?? pane.buffer?.chrome ?? "Writing"}
reading={pane.reading}
focusLine={documentPanes.active === pane.id ? focusLine : null}
{onChange}
onInsertImage={file => insertImage(file, pane.buffer)}
onRenameTitle={renameNoteTitle}
tableActions={{ onSearch: searchSelection, onExtract: (markdown, label, valid) => extractSelection(markdown, label, valid, pane.buffer) }}
linkActions={{
browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error("Could not open the app browser."); } : undefined,
defaultBrowser: target => openUrl(target),
workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id),
}}
onToggleReading={() => setReading(!pane.reading, pane.id)}
onToggleChrome={() => { focusDocumentPane(pane.id); toggleChrome(); }}
onOpenLink={(kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
/>
</div>
{/each}
</div>
</div>
</main>
{#if terminalContribution && terminalStarted}
@@ -1170,7 +1307,7 @@
items={outlineItems}
onJump={(line) => {
pluginEditorActive.set(false);
reading = false;
setReading(false);
focusLine = null;
queueMicrotask(() => {
focusLine = line;
@@ -1199,6 +1336,8 @@
.disk-review { padding: 8px 12px; max-height: 35vh; overflow: auto; flex: 0 0 auto; }
.disk-review pre { white-space: pre-wrap; user-select: text; }
.shell {
position: relative;
isolation: isolate;
height: 100vh;
display: grid;
--ribbon-width: 0px;
@@ -1207,6 +1346,39 @@
background: var(--rs-bg);
}
.workarea-background {
position: absolute;
inset: var(--rs-titlebar-height) 0 22px;
z-index: -1;
pointer-events: none;
background-color: var(--rs-new-tab-bg, var(--rs-bg));
background-image: var(--rs-background-image, var(--rs-new-tab-image, none));
background-size: var(--rs-background-layer-sizes, 100% 100%, var(--rs-background-size, cover));
background-position: var(--rs-background-layer-positions, center, var(--rs-background-position, center));
background-repeat: no-repeat;
}
.workarea-background::before,
.workarea-background::after {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
background-repeat: no-repeat;
}
.workarea-background::before {
background-image: var(--rs-background-previous-image, none);
background-size: var(--rs-background-previous-layer-sizes, 100% 100%, var(--rs-background-previous-size, cover));
background-position: var(--rs-background-previous-layer-positions, center, var(--rs-background-previous-position, center));
}
.workarea-background::after {
background-image: var(--rs-background-transition-image, none);
background-size: var(--rs-background-layer-sizes, 100% 100%, var(--rs-background-size, cover));
background-position: var(--rs-background-layer-positions, center, var(--rs-background-position, center));
}
.shell.left-open {
grid-template-columns: var(--ribbon-width) var(--left) 1px minmax(0, 1fr);
}
@@ -1232,7 +1404,7 @@
min-height: 0;
padding: 6px 5px;
overflow-y: auto;
background: var(--rs-bg-elevated);
background: var(--rs-workarea-sidebar-bg);
border-right: 1px solid var(--rs-border);
}
@@ -1315,7 +1487,7 @@
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--rs-bg);
background: transparent;
}
.center-stack {
@@ -1337,6 +1509,16 @@
position: relative;
}
.editor-host { container-type: inline-size; }
.document-panes { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.document-pane { flex: var(--pane-weight) 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.document-pane + .document-pane { border-left: 1px solid var(--rs-border); }
.document-panes.split .document-pane.focused :global(.chrome-bar) { background: var(--rs-bg-active); }
@container (max-width: 640px) {
.document-panes.split { flex-direction: column; overflow-y: auto; }
.document-panes.split .document-pane { flex: 1 0 320px; }
.document-pane + .document-pane { border-left: 0; border-top: 1px solid var(--rs-border); }
}
.editor-host.plugin-covered { display: none; }
.center { position: relative; }
.plugin-panes { position: relative; flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
@@ -1347,7 +1529,7 @@
.left,
.right {
background: var(--rs-bg-elevated);
background: var(--rs-workarea-sidebar-bg);
}
.left {
@@ -1487,7 +1669,7 @@
display: flex;
flex-direction: column;
min-height: 0;
background: var(--rs-bg-elevated);
background: transparent;
}
.bottom > :global(*) {