Release RuneStone 0.1.4 with installable plugins and settings
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
<script lang="ts">
|
||||
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
|
||||
import PluginTools from "$lib/plugins/PluginTools.svelte";
|
||||
import { onMount, tick } from "svelte";
|
||||
import { selectedEditorText } from "$lib/editor/selection";
|
||||
import { terminalShortcut } from "$lib/terminal/model";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import type { Contributions } from "$lib/plugins/contracts";
|
||||
import { isTauri } from "@tauri-apps/api/core";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { confirm } from "@tauri-apps/plugin-dialog";
|
||||
@@ -13,6 +16,8 @@
|
||||
import TextDialog from "./TextDialog.svelte";
|
||||
import QuickOpen from "./QuickOpen.svelte";
|
||||
import WorkspacePicker from "./WorkspacePicker.svelte";
|
||||
import SettingsDialog from "./SettingsDialog.svelte";
|
||||
import { DEFAULT_SETTINGS, SETTINGS_KEY, parseSettings, saveSettings, type AppSettings } from "$lib/workspace/settings";
|
||||
import FileTree from "./FileTree.svelte";
|
||||
import EditorPane from "./EditorPane.svelte";
|
||||
import TabBar from "./TabBar.svelte";
|
||||
@@ -21,7 +26,7 @@
|
||||
import WindowControls from "$lib/ui/WindowControls.svelte";
|
||||
import SearchPane from "./SearchPane.svelte";
|
||||
import BookmarksPane from "./BookmarksPane.svelte";
|
||||
import TerminalDock from "./TerminalDock.svelte";
|
||||
|
||||
import { buildOutline } from "$lib/workspace/outline";
|
||||
import {
|
||||
onWorkspaceEvent,
|
||||
@@ -46,6 +51,9 @@
|
||||
|
||||
let workspace = $state<WorkspaceInfo | null>(null);
|
||||
let workspacePicker: WorkspacePicker;
|
||||
let preferences = $state<"settings" | "help" | null>(null);
|
||||
let settings = $state<AppSettings>({ ...DEFAULT_SETTINGS });
|
||||
let settingsReady = $state(false);
|
||||
let workspaceAnchor: HTMLDivElement | undefined = $state();
|
||||
const desktop = isTauri();
|
||||
let tabs = $state<OpenBuffer[]>([]);
|
||||
@@ -67,7 +75,16 @@
|
||||
let quickOpen = $state(false);
|
||||
let terminalStarted = $state(false);
|
||||
let terminalMaximized = $state(false);
|
||||
let terminalDock: TerminalDock | undefined = $state();
|
||||
let terminalDock: TerminalSlot | undefined = $state();
|
||||
const terminalContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("terminal"); });
|
||||
const terminalEnabled = $derived(!!terminalContribution);
|
||||
|
||||
$effect(() => {
|
||||
if (!terminalEnabled) {
|
||||
terminalOpen = false; terminalStarted = false; terminalMaximized = false;
|
||||
}
|
||||
});
|
||||
|
||||
let saving = $state(false);
|
||||
let switching = false;
|
||||
let documents: Documents | null = null;
|
||||
@@ -110,18 +127,20 @@
|
||||
}
|
||||
|
||||
function toggleTerminal() {
|
||||
if (!terminalEnabled) return;
|
||||
terminalOpen = !terminalOpen;
|
||||
if (terminalOpen) terminalStarted = true;
|
||||
if (terminalOpen) { terminalStarted = true; }
|
||||
if (terminalOpen && bottomHeight < 220) bottomHeight = 260;
|
||||
}
|
||||
|
||||
async function terminalAction(action: Exclude<ReturnType<typeof terminalShortcut>, null | "toggle">) {
|
||||
async function terminalAction(action: Exclude<ReturnType<Contributions["terminal"]["shortcut"]>, null | "toggle">) {
|
||||
if (!terminalEnabled) return;
|
||||
if (!workspace) { error = "Open a workspace to start a terminal."; return; }
|
||||
const started = terminalStarted;
|
||||
terminalStarted = true; terminalOpen = true;
|
||||
if (bottomHeight < 220) bottomHeight = 260;
|
||||
await tick();
|
||||
if (action !== "new" || started) await terminalDock?.command(action);
|
||||
if (terminalEnabled && (action !== "new" || started)) await terminalDock?.command(action);
|
||||
}
|
||||
|
||||
async function terminalFile(): Promise<string | null> {
|
||||
@@ -269,6 +288,14 @@
|
||||
} catch (err) { if (documents === current) error = String(err); }
|
||||
}
|
||||
|
||||
async function openCreatedFile(entry: TreeEntry) {
|
||||
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);
|
||||
}
|
||||
|
||||
function readFileDataUrl(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
@@ -384,7 +411,7 @@
|
||||
try {
|
||||
await workspaceCreate(name.replaceAll("\\", "/"), "file");
|
||||
refreshToken += 1;
|
||||
await openFile({
|
||||
await openCreatedFile({
|
||||
name: name.split("/").pop() ?? name,
|
||||
rel_path: name.replaceAll("\\", "/"),
|
||||
kind: "file",
|
||||
@@ -394,9 +421,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onPreferencesKeydown(event: KeyboardEvent) {
|
||||
if (event.target instanceof Element && event.target.closest("dialog, [role=dialog], [role=menu]")) return;
|
||||
if ((event.ctrlKey || event.metaKey) && !event.shiftKey && !event.altKey && event.key === ",") {
|
||||
event.preventDefault(); event.stopPropagation(); preferences = "settings";
|
||||
}
|
||||
if (event.key === "F1" && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
||||
event.preventDefault(); event.stopPropagation(); preferences = "help";
|
||||
}
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (event.target instanceof Element && event.target.closest("dialog, [role=dialog], [role=menu]")) return;
|
||||
const action = terminalShortcut(event);
|
||||
const action = pluginHost.get("terminal")?.shortcut(event);
|
||||
const terminalTarget = event.target instanceof Element && !!event.target.closest(".dock");
|
||||
if (action && (["toggle", "new", "split", "window"].includes(action) || terminalTarget)) {
|
||||
event.preventDefault();
|
||||
@@ -431,7 +468,7 @@
|
||||
event.preventDefault();
|
||||
toggleChrome();
|
||||
}
|
||||
if ((event.ctrlKey || event.metaKey) && event.key === "`") {
|
||||
if (terminalEnabled && (event.ctrlKey || event.metaKey) && event.key === "`") {
|
||||
event.preventDefault();
|
||||
toggleTerminal();
|
||||
}
|
||||
@@ -540,14 +577,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
function updateSettings(next: AppSettings) {
|
||||
saveSettings(localStorage, next);
|
||||
settings = { ...next };
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
try { settings = parseSettings(localStorage.getItem(SETTINGS_KEY)); }
|
||||
catch { error = "Could not read your settings. Default settings apply until you save new settings."; }
|
||||
settingsReady = true;
|
||||
const syncSettings = (event: StorageEvent) => {
|
||||
if (event.storageArea === localStorage && (event.key === SETTINGS_KEY || event.key === null)) settings = parseSettings(event.newValue);
|
||||
};
|
||||
window.addEventListener("storage", syncSettings);
|
||||
window.addEventListener("keydown", onPreferencesKeydown, true);
|
||||
return () => {
|
||||
window.removeEventListener("storage", syncSettings);
|
||||
window.removeEventListener("keydown", onPreferencesKeydown, true);
|
||||
};
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!desktop || !settingsReady || !settings.autosaveEnabled) return;
|
||||
const timer = setInterval(() => { void autosave(); }, settings.autosaveSeconds * 1000);
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
if (!isTauri()) { status = "Desktop features require pnpm tauri dev"; return; }
|
||||
void restoreLast();
|
||||
let disposed = false;
|
||||
const unlisteners: (() => void)[] = [];
|
||||
let refreshTimer: ReturnType<typeof setTimeout>;
|
||||
// A fixed interval also saves during continuous typing; clean files never write.
|
||||
const autosaveTimer = setInterval(() => { void autosave(); }, 5_000);
|
||||
const register = (off: () => void) => { if (disposed) off(); else unlisteners.push(off); };
|
||||
void onWorkspaceEvent((event) => {
|
||||
if (event.root !== workspace?.root || event.kind === "access") return;
|
||||
@@ -576,7 +637,6 @@
|
||||
documents?.dispose();
|
||||
clearTimeout(refreshTimer);
|
||||
unlisteners.forEach(off => off());
|
||||
clearInterval(autosaveTimer);
|
||||
window.removeEventListener("focus", focus);
|
||||
};
|
||||
});
|
||||
@@ -586,6 +646,7 @@
|
||||
<svelte:window onkeydown={onKeydown} onbeforeunload={(event) => { if (hasDirty) { event.preventDefault(); event.returnValue = ""; } }} />
|
||||
<TextDialog />
|
||||
<WorkspacePicker bind:this={workspacePicker} currentRoot={workspace?.root} anchor={workspaceAnchor} onOpen={openPath} />
|
||||
{#if preferences}<SettingsDialog {settings} help={preferences === "help"} onSave={updateSettings} onClose={() => preferences = null} />{/if}
|
||||
{#if quickOpen && workspace}<QuickOpen onOpen={(entry) => void openFile(entry)} onClose={() => quickOpen = false} />{/if}
|
||||
|
||||
<div
|
||||
@@ -632,8 +693,9 @@
|
||||
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
|
||||
</div>
|
||||
<div class="header-right" data-tauri-drag-region>
|
||||
<PluginTools />
|
||||
<IconButton icon="save" label="Save" disabled={!dirty || saving} onclick={() => void save()} />
|
||||
<IconButton icon="terminal" label="Terminal" active={terminalOpen} onclick={toggleTerminal} />
|
||||
{#if terminalEnabled}<IconButton icon="terminal" label="Terminal" active={terminalOpen} onclick={toggleTerminal} />{/if}
|
||||
<IconButton
|
||||
icon="panel-right"
|
||||
label={rightOpen ? "Hide outline" : "Show outline"}
|
||||
@@ -659,7 +721,7 @@
|
||||
{refreshToken}
|
||||
keysActive={leftView === "files"}
|
||||
onCreated={(entry) => {
|
||||
void openFile(entry);
|
||||
void openCreatedFile(entry);
|
||||
}}
|
||||
onStatus={(message) => {
|
||||
status = message;
|
||||
@@ -682,6 +744,10 @@
|
||||
<IconButton icon="folder-open" label="Open folder" onclick={chooseWorkspace} />
|
||||
<span class="ws">{workspace ? workspace.name : "No workspace"}</span>
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<IconButton icon="help" label="Help and about (F1)" onclick={() => preferences = "help"} />
|
||||
<IconButton icon="settings" label="Settings (Ctrl+,)" onclick={() => preferences = "settings"} />
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -727,7 +793,7 @@
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
{#if terminalStarted}
|
||||
{#if terminalContribution && terminalStarted}
|
||||
<div
|
||||
class="gutter gutter-h" class:terminal-hidden={!terminalOpen}
|
||||
role="separator"
|
||||
@@ -736,7 +802,7 @@
|
||||
<section class="bottom" class:terminal-hidden={!terminalOpen}>
|
||||
{#if workspace}
|
||||
{#key workspace.root}
|
||||
<TerminalDock bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={toggleTerminal}
|
||||
<TerminalSlot contribution={terminalContribution} bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={toggleTerminal}
|
||||
maximized={terminalMaximized} onMaximize={() => terminalMaximized = !terminalMaximized}
|
||||
activeFile={buffer?.kind === "text" && !reading} onRunFile={terminalFile}
|
||||
getSelection={() => selectedEditorText(buffer?.id)} onConfigureTasks={configureTasks} />
|
||||
@@ -973,12 +1039,16 @@
|
||||
}
|
||||
|
||||
.footer-start {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.footer-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
|
||||
.footer-actions :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
|
||||
|
||||
.placeholder {
|
||||
margin: 12px;
|
||||
color: var(--rs-text-dim);
|
||||
|
||||
Reference in New Issue
Block a user