Update editor, workspace, Git services, appearance, and project guides
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import type { GitLineInfo } from "$lib/git/contracts";
|
||||
import EditorHost from "$lib/editor/EditorHost.svelte";
|
||||
import LiveWriter from "$lib/editor/LiveWriter.svelte";
|
||||
import { onDestroy, tick } from "svelte";
|
||||
@@ -25,6 +27,7 @@
|
||||
onOpenLink?: (kind: "md" | "wiki", target: string) => void;
|
||||
onOpenWorkspace: () => void;
|
||||
onNewFile: () => void;
|
||||
onNewNote?: (event: MouseEvent) => void;
|
||||
onQuickOpen: () => void;
|
||||
onOpenBrowser?: () => void;
|
||||
browserOpening?: boolean;
|
||||
@@ -32,7 +35,28 @@
|
||||
tableActions?: TableContextActions;
|
||||
};
|
||||
|
||||
let { buffer, tabs, chrome, reading, focusLine, onChange, onRenameTitle, onInsertImage, onToggleReading, onToggleChrome, onOpenLink, onOpenWorkspace, onNewFile, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions }: Props = $props();
|
||||
let { buffer, tabs, chrome, reading, focusLine, onChange, onRenameTitle, onInsertImage, onToggleReading, onToggleChrome, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions }: Props = $props();
|
||||
let selectedLine = $state(1);
|
||||
let lineInfo = $state<GitLineInfo | null>(null);
|
||||
const git = $derived.by(() => { void $pluginHost; return pluginHost.get("git"); });
|
||||
$effect(() => { void buffer?.id; selectedLine = 1; });
|
||||
$effect(() => {
|
||||
void buffer?.id;
|
||||
const path = buffer?.relPath, line = selectedLine, provider = git;
|
||||
const dirty = buffer?.contents !== buffer?.saved;
|
||||
const available = buffer?.kind === "text" && !reading;
|
||||
lineInfo = null;
|
||||
if (!path || !provider || !available || dirty) return;
|
||||
let cancelled = false;
|
||||
const timer = setTimeout(() => {
|
||||
void provider.blame(path, line).then(info => { if (!cancelled) lineInfo = info; }).catch(() => {});
|
||||
}, 250);
|
||||
return () => { cancelled = true; clearTimeout(timer); };
|
||||
});
|
||||
function lineDate(value: string, detailed = false) {
|
||||
const date = new Date(/^\d+$/.test(value) ? Number(value) * 1000 : value);
|
||||
return Number.isNaN(date.getTime()) ? value : detailed ? date.toLocaleString() : date.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
|
||||
}
|
||||
let previewMode = $state<"split" | "preview">("split");
|
||||
let modeControls = $state<HTMLDivElement>();
|
||||
let titleFocusId = $state<string | null>(null);
|
||||
@@ -100,6 +124,7 @@
|
||||
<button onclick={onOpenWorkspace}><Icon icon="folder-open" /> Open folder <kbd>Ctrl O</kbd></button>
|
||||
{#if hasWorkspace}
|
||||
<button onclick={onNewFile}><Icon icon="file-plus" /> New file <kbd>Ctrl N</kbd></button>
|
||||
{#if onNewNote}<button onclick={onNewNote}><Icon icon="pen" /> New note</button>{/if}
|
||||
<button onclick={onQuickOpen}><Icon icon="search" /> Find a file <kbd>Ctrl P</kbd></button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -109,6 +134,11 @@
|
||||
<div class="editor">
|
||||
<div class="chrome-bar">
|
||||
<span class="breadcrumb" title={buffer.relPath}>{buffer.relPath}</span>
|
||||
{#if lineInfo}
|
||||
<span class="line-history" title={`Line ${selectedLine} · ${lineInfo.author} · ${lineDate(lineInfo.date, true)}\n${lineInfo.summary} (${lineInfo.commit.slice(0, 8)})`}>
|
||||
<Icon icon="git" /><span>Ln {selectedLine} · {lineDate(lineInfo.date)}</span>
|
||||
</span>
|
||||
{/if}
|
||||
<div class="actions" bind:this={modeControls}>
|
||||
{#if canPreview}
|
||||
<ModeSwitcher
|
||||
@@ -141,10 +171,10 @@
|
||||
<div class="editor-wrap" class:hidden={reading && canPreview && previewMode === "preview"}>
|
||||
{#key buffer.id}
|
||||
{#if !isIde && canPreview && !reading}
|
||||
<LiveWriter {buffer} {onChange} {onRenameTitle} {onInsertImage} {onOpenLink} {focusLine} {tableActions} {shouldFocusOnMount}
|
||||
<LiveWriter {buffer} {onChange} {onRenameTitle} {onInsertImage} {onOpenLink} {focusLine} {tableActions} {shouldFocusOnMount} onSelectionLine={(line) => selectedLine = line}
|
||||
focusTitle={titleFocusId === buffer.id} onTitleFocused={() => { titleFocusId = null; }} />
|
||||
{:else}
|
||||
<EditorHost {buffer} {chrome} {onChange} {onInsertImage} {focusLine} {tableActions} {shouldFocusOnMount} />
|
||||
<EditorHost {buffer} {chrome} {onChange} {onInsertImage} {onOpenLink} {focusLine} {tableActions} {shouldFocusOnMount} onSelectionLine={(line) => selectedLine = line} />
|
||||
{/if}
|
||||
{/key}
|
||||
</div>
|
||||
@@ -161,6 +191,9 @@
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.line-history { display: inline-flex; align-items: center; gap: 5px; min-width: 0; max-width: 40%; color: var(--rs-text-dim); font-size: 11px; white-space: nowrap; }
|
||||
.line-history span { overflow: hidden; text-overflow: ellipsis; }
|
||||
.line-history :global(svg) { width: 14px; height: 14px; flex-shrink: 0; }
|
||||
.breadcrumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; }
|
||||
.welcome-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
|
||||
.welcome-actions button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); padding: 10px 14px; }
|
||||
@@ -193,9 +226,10 @@
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
height: 42px;
|
||||
min-height: 34px;
|
||||
flex-shrink: 0;
|
||||
padding: 0 10px;
|
||||
background: var(--rs-bg-elevated);
|
||||
background: var(--rs-bg);
|
||||
border-bottom: 1px solid var(--rs-border);
|
||||
color: var(--rs-text-dim);
|
||||
flex: 0 0 auto;
|
||||
|
||||
Reference in New Issue
Block a user