Add completion, browser integration, and workspace improvements
This commit is contained in:
+169
-25
@@ -1,25 +1,29 @@
|
||||
<script lang="ts">
|
||||
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
|
||||
import PluginTools from "$lib/plugins/PluginTools.svelte";
|
||||
import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte";
|
||||
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
||||
import PluginEditorTab from "$lib/plugins/PluginEditorTab.svelte";
|
||||
import { pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginDocumentRename, cancelPluginDocumentOpen } from "$lib/plugins/external";
|
||||
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabDragData, dropPluginTab, findPluginEditor } from "$lib/plugins/external";
|
||||
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
|
||||
import { pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external";
|
||||
import { onMount, tick } from "svelte";
|
||||
import { selectedEditorText } from "$lib/editor/selection";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import type { Contributions } from "$lib/plugins/contracts";
|
||||
import { isTauri } from "@tauri-apps/api/core";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { confirm } from "@tauri-apps/plugin-dialog";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { Documents } from "$lib/workspace/documents";
|
||||
import { tabsToClose, type TabCloseScope } from "$lib/workspace/tabActions";
|
||||
import { orderWorkbenchTabs, type WorkbenchTab } from "$lib/workspace/workbenchTabs";
|
||||
import type { ActionMenuItem } from "$lib/ui/actionMenu";
|
||||
import { requestText } from "$lib/workspace/dialogs.svelte";
|
||||
import TextDialog from "./TextDialog.svelte";
|
||||
import QuickOpen from "./QuickOpen.svelte";
|
||||
import WorkspacePicker from "./WorkspacePicker.svelte";
|
||||
import SettingsDialog from "./SettingsDialog.svelte";
|
||||
import BrowserSlot from "$lib/plugins/BrowserSlot.svelte";
|
||||
import { DEFAULT_SETTINGS, SETTINGS_KEY, parseSettings, saveSettings, type AppSettings } from "$lib/workspace/settings";
|
||||
import FileTree from "./FileTree.svelte";
|
||||
import EditorPane from "./EditorPane.svelte";
|
||||
@@ -55,6 +59,15 @@
|
||||
let workspace = $state<WorkspaceInfo | null>(null);
|
||||
let workspacePicker: WorkspacePicker;
|
||||
let preferences = $state<"settings" | "help" | null>(null);
|
||||
let openingSettings = false;
|
||||
async function openSettings() {
|
||||
if (!desktop) { preferences = "settings"; return; }
|
||||
if (openingSettings) return;
|
||||
openingSettings = true;
|
||||
try { await invoke("settings_open_window"); }
|
||||
catch (reason) { error = `Could not open settings: ${String(reason)}`; }
|
||||
finally { openingSettings = false; }
|
||||
}
|
||||
let settings = $state<AppSettings>({ ...DEFAULT_SETTINGS });
|
||||
let settingsReady = $state(false);
|
||||
let workspaceAnchor: HTMLDivElement | undefined = $state();
|
||||
@@ -81,6 +94,28 @@
|
||||
let terminalDock: TerminalSlot | undefined = $state();
|
||||
const terminalContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("terminal"); });
|
||||
const terminalEnabled = $derived(!!terminalContribution);
|
||||
const browserContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("browser"); });
|
||||
let browserOpening = $state(false);
|
||||
async function openBrowser() {
|
||||
if (browserOpening || !browserContribution?.newTab) return;
|
||||
browserOpening = true;
|
||||
const current = documents;
|
||||
const empty = !editorPluginVisible && buffer?.kind === "empty" ? buffer : null;
|
||||
const existing = new Set($pluginEditors.map(view => view.key));
|
||||
try {
|
||||
await browserContribution.newTab();
|
||||
const opened = $pluginView;
|
||||
if (empty && documents === current && current?.buffers.some(tab => tab.id === empty.id && tab.kind === "empty")
|
||||
&& opened?.placement === "editor" && !existing.has(opened.key)) {
|
||||
tabOrder = workingTabs.map(tab => tab.id === (empty.tabId ?? empty.id) ? opened.key : tab.id).filter((id, index, order) => order.indexOf(id) === index);
|
||||
if (empty.pinned && !opened.pinned) pinPluginEditor(opened.key);
|
||||
current.close(empty.relPath);
|
||||
}
|
||||
error = null;
|
||||
}
|
||||
catch (reason) { error = String(reason); }
|
||||
finally { browserOpening = false; }
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!terminalEnabled) {
|
||||
@@ -113,6 +148,41 @@
|
||||
let centerStack: HTMLElement | undefined = $state();
|
||||
|
||||
const editorPluginVisible = $derived($pluginView?.placement === "editor" && $pluginEditorActive);
|
||||
type EditorTab = WorkbenchTab & ({ buffer: OpenBuffer } | { plugin: OpenPluginView });
|
||||
let tabOrder = $state<string[]>([]);
|
||||
const availableTabs = $derived<EditorTab[]>([
|
||||
...tabs.map(tab => ({
|
||||
id: tab.tabId ?? tab.id, relPath: tab.relPath, name: tab.name,
|
||||
title: tab.kind === "empty" ? tab.name : tab.relPath,
|
||||
dirty: tab.contents !== tab.saved, pinned: !!tab.pinned, buffer: tab,
|
||||
})),
|
||||
...$pluginEditors.map(plugin => ({
|
||||
id: plugin.key, relPath: `plugin:${plugin.key}`, name: plugin.title,
|
||||
title: plugin.document?.path ?? plugin.title,
|
||||
icon: plugin.icon === "file" ? "files" as const : plugin.icon ?? "puzzle" as const,
|
||||
iconImage: plugin.iconImage,
|
||||
panelId: `plugin-editor-${plugin.key}`, pinned: !!plugin.pinned, draggable: plugin.draggable, plugin,
|
||||
})),
|
||||
]);
|
||||
const workingTabs = $derived(orderWorkbenchTabs(availableTabs, tabOrder));
|
||||
function workingTabDragData(tab: WorkbenchTab) {
|
||||
const view = $pluginEditors.find(view => view.key === tab.id);
|
||||
return view ? pluginTabDragData(view) : undefined;
|
||||
}
|
||||
async function receiveTab(data: string, index: number) {
|
||||
try {
|
||||
await dropPluginTab(data);
|
||||
if ($pluginView?.placement === "editor") moveWorkingTab(`plugin:${$pluginView.key}`, index);
|
||||
error = null;
|
||||
} catch (reason) { error = String(reason); }
|
||||
}
|
||||
const activeTabPath = $derived(editorPluginVisible && $pluginView ? `plugin:${$pluginView.key}` : activePath);
|
||||
const activeSplit = $derived($pluginSplits.find(tree => $pluginView && containsPane(tree, $pluginView.key)));
|
||||
const pluginBounds = $derived(activeSplit ? paneBounds(activeSplit) : $pluginView ? paneBounds($pluginView.key) : {});
|
||||
$effect(() => {
|
||||
const order = workingTabs.map(tab => tab.id);
|
||||
if (order.length !== tabOrder.length || order.some((id, index) => id !== tabOrder[index])) tabOrder = order;
|
||||
});
|
||||
const dirty = $derived(buffer !== null && buffer.contents !== buffer.saved);
|
||||
const isIde = $derived(view === "Ide");
|
||||
const outlineItems = $derived(
|
||||
@@ -213,6 +283,38 @@
|
||||
status = documents?.active?.kind === "empty" ? "New tab" : relPath;
|
||||
}
|
||||
|
||||
function selectWorkingTab(path: string) {
|
||||
const tab = workingTabs.find(tab => tab.relPath === path);
|
||||
if (!tab) return;
|
||||
if ("plugin" in tab) selectPluginEditor(tab.plugin);
|
||||
else selectTab(path);
|
||||
}
|
||||
|
||||
function moveWorkingTab(path: string, index: number) {
|
||||
const from = workingTabs.findIndex(tab => tab.relPath === path);
|
||||
if (from < 0 || !Number.isInteger(index)) return;
|
||||
const ordered = [...workingTabs];
|
||||
const [tab] = ordered.splice(from, 1);
|
||||
const destination = Math.max(0, Math.min(index, ordered.length));
|
||||
ordered.splice(destination, 0, tab);
|
||||
tabOrder = ordered.map(tab => tab.id);
|
||||
if ("buffer" in tab) documents?.move(path, ordered.slice(0, destination).filter(tab => "buffer" in tab).length);
|
||||
}
|
||||
|
||||
function workingTabFileActions(item: WorkbenchTab): ActionMenuItem[] {
|
||||
const tab = workingTabs.find(tab => tab.id === item.id);
|
||||
return tab && "buffer" in tab ? tabFileActions(tab.buffer) : [];
|
||||
}
|
||||
function workingTabActions(item: WorkbenchTab): ActionMenuItem[] {
|
||||
const tab = workingTabs.find(tab => tab.id === item.id);
|
||||
return tab && "plugin" in tab ? pluginTabActions(tab.plugin) : [];
|
||||
}
|
||||
function pinWorkingTab(path: string) {
|
||||
const tab = workingTabs.find(tab => tab.relPath === path);
|
||||
if (tab && "plugin" in tab) pinPluginEditor(tab.plugin.key);
|
||||
else documents?.togglePin(path);
|
||||
}
|
||||
|
||||
function newTab() {
|
||||
cancelPluginDocumentOpen();
|
||||
if (switching) return;
|
||||
@@ -231,19 +333,27 @@
|
||||
|
||||
async function closeTabs(path: string, scope: TabCloseScope) {
|
||||
const current = documents;
|
||||
if (!current || closingTabs || switching) return;
|
||||
if (closingTabs || switching) return;
|
||||
closingTabs = true;
|
||||
try {
|
||||
const targets = tabsToClose(current.buffers, path, scope);
|
||||
const targets = tabsToClose(workingTabs, path, scope);
|
||||
for (const target of targets) {
|
||||
if (documents !== current || switching) break;
|
||||
const tab = current.buffers.find(item => item.id === target.id);
|
||||
if (!tab || (scope !== "one" && tab.pinned)) continue;
|
||||
const contents = tab.contents;
|
||||
if (contents !== tab.saved && !await confirm(`Discard unsaved edits in ${tab.name}?`, { title: "Close document", kind: "warning" })) break;
|
||||
if (documents !== current || switching || tab.contents !== contents) break;
|
||||
if (scope !== "one" && tab.pinned) continue;
|
||||
current.close(tab.relPath);
|
||||
const tab = "buffer" in target ? current?.buffers.find(item => item.id === target.buffer.id) : undefined;
|
||||
if ("buffer" in target) {
|
||||
if (!tab || (scope !== "one" && tab.pinned)) continue;
|
||||
const contents = tab.contents;
|
||||
if (contents !== tab.saved && !await confirm(`Discard unsaved edits in ${tab.name}?`, { title: "Close document", kind: "warning" })) break;
|
||||
if (documents !== current || switching || tab.contents !== contents) break;
|
||||
if (scope !== "one" && tab.pinned) continue;
|
||||
}
|
||||
const index = workingTabs.findIndex(item => item.id === target.id);
|
||||
if (index < 0) continue;
|
||||
const selected = workingTabs[index].relPath === activeTabPath
|
||||
? (workingTabs[index + 1] ?? workingTabs[index - 1])?.relPath : activeTabPath;
|
||||
if ("plugin" in target) closePluginEditor(target.plugin.key);
|
||||
else if (tab) current?.close(tab.relPath);
|
||||
if (selected && selected !== activeTabPath) selectWorkingTab(selected);
|
||||
}
|
||||
} catch (err) { error = String(err); }
|
||||
finally { closingTabs = false; }
|
||||
@@ -437,7 +547,7 @@
|
||||
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";
|
||||
event.preventDefault(); event.stopPropagation(); void openSettings();
|
||||
}
|
||||
if (event.key === "F1" && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
||||
event.preventDefault(); event.stopPropagation(); preferences = "help";
|
||||
@@ -445,7 +555,11 @@
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (event.defaultPrevented) return;
|
||||
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.toLowerCase() === "f" && editorPluginVisible && $pluginView) {
|
||||
if (findPluginEditor($pluginView)) { event.preventDefault(); return; }
|
||||
}
|
||||
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)) {
|
||||
@@ -488,7 +602,7 @@
|
||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "w") {
|
||||
event.preventDefault();
|
||||
if (editorPluginVisible) {
|
||||
if ($pluginView) closePluginEditor($pluginView.key);
|
||||
if (activeTabPath) void closeTab(activeTabPath);
|
||||
} else if (activePath) {
|
||||
closeTab(activePath);
|
||||
}
|
||||
@@ -561,7 +675,10 @@
|
||||
|
||||
async function openLink(kind: "md" | "wiki", target: string) {
|
||||
if (/^(https?:\/\/|mailto:)/i.test(target)) {
|
||||
try { await openUrl(target); } catch (err) { error = String(err); }
|
||||
try {
|
||||
if (/^https?:\/\//i.test(target) && await pluginHost.get("browser")?.open(target)) return;
|
||||
await openUrl(target);
|
||||
} catch (err) { error = String(err); }
|
||||
return;
|
||||
}
|
||||
const rels = linkCandidates(activePath ?? "", target, kind);
|
||||
@@ -718,17 +835,17 @@
|
||||
/>
|
||||
</div>
|
||||
<div class="header-center" data-tauri-drag-region>
|
||||
{#if tabs.length > 0}
|
||||
<TabBar {tabs} activePath={editorPluginVisible ? null : activePath} onSelect={selectTab} onClose={closeTab}
|
||||
onCloseTabs={(path, scope) => void closeTabs(path, scope)} onPin={(path) => documents?.togglePin(path)}
|
||||
fileActions={tabFileActions} onMove={(path, index) => documents?.move(path, index)} />
|
||||
{/if}
|
||||
<PluginEditorTab />
|
||||
<TabBar tabs={workingTabs} activePath={activeTabPath} onSelect={selectWorkingTab} onClose={closeTab}
|
||||
onCloseTabs={(path, scope) => void closeTabs(path, scope)} onPin={pinWorkingTab}
|
||||
fileActions={workingTabFileActions} tabActions={workingTabActions} onMove={moveWorkingTab}
|
||||
tabDragData={workingTabDragData} onDropTab={(data, index) => void receiveTab(data, index)} />
|
||||
<IconButton icon="plus" label="New tab (Ctrl T)" onclick={newTab} />
|
||||
<PluginAccessMenu surface="open" />
|
||||
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
|
||||
</div>
|
||||
<div class="header-right" data-tauri-drag-region>
|
||||
<PluginTools />
|
||||
<PluginAccessMenu surface="commands" />
|
||||
<IconButton icon="save" label="Save" disabled={editorPluginVisible || !dirty || saving} onclick={() => void save()} />
|
||||
{#if terminalEnabled}<IconButton icon="terminal" label="Terminal" active={terminalOpen} onclick={toggleTerminal} />{/if}
|
||||
<IconButton
|
||||
@@ -744,7 +861,7 @@
|
||||
<nav class="plugin-ribbon" aria-label="Plugin shortcuts" hidden={$pluginNavigation.length === 0}>
|
||||
{#each $pluginNavigation as item (`${item.owner}:${item.id}`)}
|
||||
<IconButton
|
||||
icon={item.icon === "list" || item.icon === "kanban" ? item.icon : "puzzle"}
|
||||
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" ? item.icon : "puzzle"}
|
||||
label={item.title}
|
||||
side="right"
|
||||
active={$pluginView?.owner === item.owner && $pluginView?.id === item.id && !$pluginView?.document && ($pluginView?.placement === "dialog" || $pluginEditorActive)}
|
||||
@@ -757,7 +874,7 @@
|
||||
<aside class="left">
|
||||
<div class="left-body">
|
||||
{#if !workspace}
|
||||
<p class="placeholder">No folder is open.</p>
|
||||
{#if leftView === "bookmarks"}<BrowserSlot kind="bookmarks" />{:else}<p class="placeholder">No folder is open.</p>{/if}
|
||||
{:else}
|
||||
<div class="left-stack">
|
||||
<div class="left-layer" class:shown={leftView === "files"}>
|
||||
@@ -793,7 +910,7 @@
|
||||
</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"} />
|
||||
<IconButton icon="settings" label="Settings (Ctrl+,)" onclick={() => void openSettings()} />
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -807,7 +924,25 @@
|
||||
|
||||
<div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}>
|
||||
<main class="center">
|
||||
{#each $pluginEditors as view (view.key)}<PluginEditor {view} />{/each}
|
||||
<div class="plugin-panes" class:inactive={!editorPluginVisible}>
|
||||
{#each $pluginEditors as pane (pane.key)}
|
||||
{@const bounds = pluginBounds[pane.key]}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions (Focus selects the pane that owns the input.) -->
|
||||
<div class="plugin-pane" class:inactive={!bounds} class:split={!!activeSplit} class:focused={$pluginView?.key === pane.key}
|
||||
style:left={`${bounds?.left ?? 0}%`} style:top={`${bounds?.top ?? 0}%`}
|
||||
style:width={`${bounds?.width ?? 100}%`} style:height={`${bounds?.height ?? 100}%`}
|
||||
onfocusin={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }}
|
||||
onpointerdown={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }}>
|
||||
{#if activeSplit && bounds}
|
||||
<TabBar tabs={workingTabs.filter(tab => tab.id === pane.key)} activePath={activeTabPath}
|
||||
onSelect={selectWorkingTab} onClose={closeTab} onMove={moveWorkingTab} onPin={pinWorkingTab}
|
||||
onCloseTabs={(path, scope) => void closeTabs(path, scope)} fileActions={workingTabFileActions} tabActions={workingTabActions}
|
||||
tabDragData={workingTabDragData} onDropTab={(data, index) => void receiveTab(data, index)} />
|
||||
{/if}
|
||||
<PluginEditor view={pane} />
|
||||
</div>
|
||||
{/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>
|
||||
@@ -827,6 +962,8 @@
|
||||
onOpenWorkspace={() => void chooseWorkspace()}
|
||||
onNewFile={() => void newFile()}
|
||||
onQuickOpen={() => quickOpen = true}
|
||||
onOpenBrowser={browserContribution?.newTab ? () => void openBrowser() : undefined}
|
||||
{browserOpening}
|
||||
{buffer}
|
||||
chrome={view}
|
||||
{reading}
|
||||
@@ -997,6 +1134,7 @@
|
||||
background: transparent;
|
||||
border-bottom: 0;
|
||||
}
|
||||
.header-center :global(.tabs:empty) { min-width: 80px; }
|
||||
|
||||
.header-center :global(.tab) {
|
||||
max-width: 180px;
|
||||
@@ -1047,6 +1185,12 @@
|
||||
}
|
||||
|
||||
.editor-host.plugin-covered { display: none; }
|
||||
.center { position: relative; }
|
||||
.plugin-panes { position: relative; flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
|
||||
.plugin-pane { position: absolute; display: flex; flex-direction: column; min-width: 0; min-height: 0; box-sizing: border-box; }
|
||||
.plugin-pane.split { border: 1px solid var(--rs-border); }
|
||||
.plugin-pane.split.focused { border-color: var(--rs-accent); }
|
||||
.plugin-panes.inactive, .plugin-pane.inactive { display: none; }
|
||||
|
||||
.left,
|
||||
.right {
|
||||
|
||||
Reference in New Issue
Block a user