Show one view control and name the file once
Phase 5-3. - One radio group shows Write, Source, and Read at all times, with an icon and a name. Narrow panes show only the icons. The arrow keys move the choice, and the group has one Tab stop. The current choice gets the selection fill and an accent bar. Hover gets only a fill. - A Split toggle shows Read beside Write or Source. Each document pane keeps a split flag beside its reading flag. Read ends Split. - Ctrl+Shift+E switches between Read and the editor. Ctrl+E still switches between Write and Source. - "IDE" becomes "Source" in the Chrome type, the tab menu (a View submenu), the status bar, the catalog, the tests, and the docs. - Settings, General, File name title hides the title in Write and Read. It is on by default. - The breadcrumb shows only the folder of the file. The status bar shows the view, not the path. - ModeSwitcher.svelte and its hover test are gone. The new test layout/viewModes covers the control. - The command palette from 5-2 gets its row in docs/menu-surfaces.json. - The user guide Format table is whole again. The 5-2 edit had put the Paragraph and Insert rows under the shortcut table. - 8 new catalog rows and 10 removed rows, in French, Japanese, and Simplified Chinese. - Docs: UI-049, the user guide, ui-design.md, document-tools.md, development.md, and the README feature list. Tests: the new layout/viewModes, new cases in documentPanes.spec.ts and settings.spec.ts, and the chooseView harness helper. 21 smoke tests use the new control. Tests that read the full path from the breadcrumb now read its tooltip.
This commit is contained in:
@@ -7,10 +7,11 @@
|
||||
import type { Documents } from "$lib/workspace/documents.svelte";
|
||||
import type { OpenBuffer } from "$lib/workspace/types";
|
||||
import EditorPane from "./EditorPane.svelte";
|
||||
import type { ViewMode } from "./ViewModes.svelte";
|
||||
import TabBar from "./TabBar.svelte";
|
||||
|
||||
type EditorProps = ComponentProps<typeof EditorPane>;
|
||||
type DocumentView = { id: string; reading: boolean; buffer: OpenBuffer | null; bounds: { width: number } };
|
||||
type DocumentView = { id: string; reading: boolean; split: boolean; buffer: OpenBuffer | null; bounds: { width: number } };
|
||||
type Bounds = { left: number; top: number; width: number; height: number };
|
||||
type Props = {
|
||||
editorPluginVisible: boolean;
|
||||
@@ -39,13 +40,13 @@
|
||||
onRenameTitle: EditorProps["onRenameTitle"];
|
||||
tableActions: (pane: DocumentView) => EditorProps["tableActions"];
|
||||
linkActions: (pane: DocumentView) => EditorProps["linkActions"];
|
||||
onToggleReading: (pane: DocumentView) => void;
|
||||
onToggleChrome: (pane: DocumentView) => void;
|
||||
onView: (pane: DocumentView, view: ViewMode) => void;
|
||||
onSplitView: (pane: DocumentView, split: boolean) => void;
|
||||
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
|
||||
};
|
||||
let { editorPluginVisible, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, activePane, paneComponents = $bindable(),
|
||||
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
|
||||
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onToggleReading, onToggleChrome, onOpenLink }: Props = $props();
|
||||
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onOpenLink }: Props = $props();
|
||||
</script>
|
||||
|
||||
<main class="center">
|
||||
@@ -100,14 +101,15 @@
|
||||
buffer={pane.buffer}
|
||||
chrome={pane.buffer?.chromeOverride ?? pane.buffer?.chrome ?? "Writing"}
|
||||
reading={pane.reading}
|
||||
split={pane.split}
|
||||
focusLine={activePane === pane.id ? focusLine : null}
|
||||
{onChange}
|
||||
onInsertImage={file => onInsertImage(file, pane.buffer)}
|
||||
{onRenameTitle}
|
||||
tableActions={tableActions(pane)}
|
||||
linkActions={linkActions(pane)}
|
||||
onToggleReading={() => onToggleReading(pane)}
|
||||
onToggleChrome={() => onToggleChrome(pane)}
|
||||
onView={view => onView(pane, view)}
|
||||
onSplit={next => onSplitView(pane, next)}
|
||||
onOpenLink={(kind, target) => onOpenLink(pane, kind, target)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import IconButton from "$lib/ui/IconButton.svelte";
|
||||
import ImageViewer from "./ImageViewer.svelte";
|
||||
import MarkdownView from "./MarkdownView.svelte";
|
||||
import ModeSwitcher from "$lib/ui/ModeSwitcher.svelte";
|
||||
import ViewModes, { type ViewMode } from "./ViewModes.svelte";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import { isMarkdownPath } from "$lib/workspace/media";
|
||||
import type { Chrome, OpenBuffer } from "$lib/workspace/types";
|
||||
@@ -24,12 +24,13 @@
|
||||
tabs: OpenBuffer[];
|
||||
chrome: Chrome;
|
||||
reading: boolean;
|
||||
split: boolean;
|
||||
focusLine: number | null;
|
||||
onChange: (value: string, id: string) => void;
|
||||
onRenameTitle?: (id: string, title: string) => Promise<void>;
|
||||
onInsertImage?: (file: File) => Promise<string | null>;
|
||||
onToggleReading?: () => void;
|
||||
onToggleChrome?: () => void;
|
||||
onView?: (view: ViewMode) => void;
|
||||
onSplit?: (split: boolean) => void;
|
||||
onOpenLink?: (kind: "md" | "wiki", target: string) => void;
|
||||
onOpenWorkspace: () => void;
|
||||
onNewFile: () => void;
|
||||
@@ -44,7 +45,7 @@
|
||||
onCloseSplit?: () => void;
|
||||
};
|
||||
|
||||
let { buffer, tabs, chrome, reading, focusLine, onChange, onRenameTitle, onInsertImage, onToggleReading, onToggleChrome, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions, linkActions, active = true, onCloseSplit }: Props = $props();
|
||||
let { buffer, tabs, chrome, reading, split, focusLine, onChange, onRenameTitle, onInsertImage, onView, onSplit, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions, linkActions, active = true, onCloseSplit }: Props = $props();
|
||||
let selectedLine = $state(1);
|
||||
let lineInfo = $state<GitLineInfo | null>(null);
|
||||
const git = $derived.by(() => { void $pluginHost; return pluginHost.get("git"); });
|
||||
@@ -53,7 +54,7 @@
|
||||
void buffer?.id;
|
||||
const path = buffer?.relPath, line = selectedLine, provider = git;
|
||||
const dirty = buffer?.contents !== buffer?.saved;
|
||||
const available = buffer?.kind === "text" && !reading;
|
||||
const available = buffer?.kind === "text" && !readOnly;
|
||||
lineInfo = null;
|
||||
if (!path || !provider || !available || dirty) return;
|
||||
let cancelled = false;
|
||||
@@ -66,14 +67,13 @@
|
||||
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);
|
||||
let element: HTMLDivElement | undefined = $state();
|
||||
let documentEditor: DocumentEditor | undefined = $state();
|
||||
let readingFind = $state.raw<FindTarget>();
|
||||
let readingFindPanel = $state<FindPanel>();
|
||||
$effect(() => { void buffer?.id; void reading; void previewMode; readingFind = undefined; });
|
||||
$effect(() => { void buffer?.id; void reading; void split; readingFind = undefined; });
|
||||
async function documentSearch(event: KeyboardEvent) {
|
||||
if (event.target instanceof Element && event.target.closest('[role="menu"], dialog, [role="dialog"]')) return;
|
||||
const key = event.key.toLowerCase();
|
||||
@@ -81,9 +81,9 @@
|
||||
const advance = key === "f3" && !event.ctrlKey && !event.metaKey && !event.altKey;
|
||||
if ((!open && !advance) || buffer?.kind !== "text") return;
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
const inReading = reading && (previewMode === "preview" || event.target instanceof Element && (!!event.target.closest(".md-page") || !!readingFind && !!event.target.closest(".rs-find-bar")));
|
||||
const inReading = readOnly || splitView && event.target instanceof Element && (!!event.target.closest(".md-page") || !!readingFind && !!event.target.closest(".rs-find-bar"));
|
||||
if (inReading) {
|
||||
const root = element?.querySelector<HTMLElement>(".reading");
|
||||
const root = element?.querySelector<HTMLElement>(".md-page > .reading");
|
||||
if (!root) return;
|
||||
documentEditor?.closeFind();
|
||||
readingFind ??= readingSearch(root, () => { readingFind = undefined; });
|
||||
@@ -98,7 +98,7 @@
|
||||
}
|
||||
const shouldFocusOnMount = () => active && !modeControls?.contains(document.activeElement);
|
||||
export function focusEditor() {
|
||||
if (reading) element?.querySelector<HTMLElement>(".reading")?.focus({ preventScroll: true });
|
||||
if (readOnly) element?.querySelector<HTMLElement>(".md-page > .reading")?.focus({ preventScroll: true });
|
||||
else documentEditor?.focus();
|
||||
}
|
||||
export function focusTitle(id: string) {
|
||||
@@ -138,19 +138,13 @@
|
||||
} };
|
||||
}
|
||||
|
||||
const isIde = $derived(chrome === "Ide");
|
||||
const isImage = $derived(buffer?.kind === "image");
|
||||
const canPreview = $derived(buffer !== null && buffer.kind === "text" && isMarkdownPath(buffer.relPath));
|
||||
const documentMode = $derived(!reading ? "edit" : previewMode === "preview" ? "read" : "split");
|
||||
|
||||
function setDocumentMode(mode: string) {
|
||||
if (mode !== "edit") previewMode = mode === "read" ? "preview" : "split";
|
||||
if (reading !== (mode !== "edit")) onToggleReading?.();
|
||||
}
|
||||
|
||||
export function toggleReadingView() {
|
||||
setDocumentMode(reading ? "edit" : "read");
|
||||
}
|
||||
const readOnly = $derived(reading && canPreview);
|
||||
const splitView = $derived(split && canPreview && !reading);
|
||||
const view: ViewMode = $derived(readOnly ? "read" : chrome === "Source" ? "source" : "write");
|
||||
// The tab already names the file, so the breadcrumb shows only its folder.
|
||||
const folder = $derived(buffer?.relPath.includes("/") ? buffer.relPath.slice(0, buffer.relPath.lastIndexOf("/")).split("/").join(" / ") : "");
|
||||
</script>
|
||||
|
||||
{#if !buffer || buffer.kind === "empty"}
|
||||
@@ -174,7 +168,7 @@
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions (Capture document shortcuts before nested editor handlers.) -->
|
||||
<div class="editor" class:pane-active={active} bind:this={element} onkeydowncapture={documentSearch}>
|
||||
<div class="chrome-bar">
|
||||
<span class="breadcrumb" title={buffer.relPath}>{buffer.relPath}</span>
|
||||
<span class="breadcrumb" title={buffer.relPath}>{folder}</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>
|
||||
@@ -182,43 +176,22 @@
|
||||
{/if}
|
||||
<div class="actions" bind:this={modeControls}>
|
||||
{#if onCloseSplit}<IconButton icon="close" label={$t("Close split")} onclick={onCloseSplit} />{/if}
|
||||
{#if canPreview}
|
||||
<ModeSwitcher
|
||||
label={$t("Document view")}
|
||||
value={documentMode}
|
||||
options={[
|
||||
{ value: "edit", label: $t("Edit"), icon: "pen" },
|
||||
{ value: "read", label: $t("Read"), icon: "book-open" },
|
||||
{ value: "split", label: $t("Split"), icon: "split" },
|
||||
]}
|
||||
onchange={setDocumentMode}
|
||||
/>
|
||||
{/if}
|
||||
<ModeSwitcher
|
||||
label={$t("Editor layout")}
|
||||
value={chrome}
|
||||
options={[
|
||||
{ value: "Ide", label: $t("IDE"), icon: "code" },
|
||||
{ value: "Writing", label: $t("Writer"), icon: "text" },
|
||||
]}
|
||||
shortcut={` (${commandShortcut("toggle-layout")})`}
|
||||
onchange={(mode) => { if (mode !== chrome) onToggleChrome?.(); }}
|
||||
/>
|
||||
{#if !isImage}<ViewModes {view} split={splitView} readable={canPreview} onView={next => onView?.(next)} onSplit={next => onSplit?.(next)} />{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if readingFind}<FindPanel bind:this={readingFindPanel} target={readingFind} />{/if}
|
||||
<div class="body" class:split={reading && canPreview && previewMode === "split"}>
|
||||
<div class="body" class:split={splitView}>
|
||||
{#if isImage && buffer.imageUrl}
|
||||
<ImageViewer src={buffer.imageUrl} name={buffer.name} />
|
||||
{:else}
|
||||
<div class="editor-wrap" class:hidden={reading && canPreview && previewMode === "preview"}>
|
||||
<div class="editor-wrap" class:hidden={readOnly}>
|
||||
{#key buffer.id}
|
||||
<DocumentEditor bind:this={documentEditor} {buffer} mode={!isIde && canPreview && !reading ? "write" : "source"} {chrome}
|
||||
<DocumentEditor bind:this={documentEditor} {buffer} mode={chrome === "Writing" && canPreview && !readOnly ? "write" : "source"} {chrome}
|
||||
{onChange} {onRenameTitle} {onInsertImage} {onOpenLink} {linkActions} {focusLine} {tableActions} {shouldFocusOnMount} onSelectionLine={(line) => selectedLine = line}
|
||||
focusTitle={titleFocusId === buffer.id} onTitleFocused={() => { titleFocusId = null; }} />
|
||||
{/key}
|
||||
</div>
|
||||
{#if reading && canPreview}
|
||||
{#if readOnly || splitView}
|
||||
{#key buffer.id}
|
||||
<div class="md-page" use:rememberPreviewScroll={buffer.id}>
|
||||
<MarkdownView noteRel={buffer.relPath} contents={buffer.contents} {focusLine} {onOpenLink} {linkActions} onSearch={tableActions?.onSearch} />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { isRemoteImage, resolveImageRel, markdownTitle } from "$lib/workspace/media";
|
||||
import { imageControls } from "$lib/editor/imageControls";
|
||||
import { readerHeadingFolding } from "$lib/editor/headingFolding";
|
||||
import { fileTitleVisible } from "$lib/editor/fileTitle";
|
||||
import { documentHeadings } from "$lib/workspace/headingLinks";
|
||||
import "$lib/editor/headingFolding.css";
|
||||
|
||||
@@ -193,7 +194,7 @@
|
||||
}}
|
||||
>
|
||||
{#if menuError}<p role="alert">{menuError}</p>{/if}
|
||||
<h1 class="document-title">{markdownTitle(noteRel)}</h1>
|
||||
{#if $fileTitleVisible}<h1 class="document-title">{markdownTitle(noteRel)}</h1>{/if}
|
||||
{#if onEditBlock}
|
||||
{#each sections.filter(section => !editing || section.start < editing.start) as section (section.start)}
|
||||
<div class="md-edit-block" role="button" tabindex="0" aria-label={$t("Edit document block")} data-start={section.start} data-end={section.end}>{@html section.html}</div>
|
||||
|
||||
@@ -138,6 +138,13 @@
|
||||
<p class="intro">{$t("Choose how RuneStone saves your work.")}</p>
|
||||
<h3>{$t('Language')}</h3>
|
||||
<div class="card"><div class="setting-row language-row"><div><label for="language-picker">{$t('Display language')}</label><p>{$t('Choose the language for RuneStone controls.')}</p></div><button id="language-picker" class="text-button language-picker" aria-haspopup="menu" onclick={languagePicker}><Icon icon="globe" />{LANGUAGES.find(item => item.id === $locale)?.name}<Icon icon="chevron-down" /></button></div></div>
|
||||
<h3>{$t("Documents")}</h3>
|
||||
<div class="card">
|
||||
<div class="setting-row">
|
||||
<div><label for="show-file-title">{$t("File name title")}</label><p id="file-title-description">{$t("Show the file name above each Markdown note in Write and Read.")}</p></div>
|
||||
<input id="show-file-title" class="switch" type="checkbox" role="switch" aria-describedby="file-title-description" checked={settings.showFileTitle} onchange={event => apply({ ...settings, showFileTitle: event.currentTarget.checked })} />
|
||||
</div>
|
||||
</div>
|
||||
<h3>{$t("Tables")}</h3>
|
||||
<div class="card">
|
||||
<div class="setting-row">
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<script lang="ts">
|
||||
// The status bar at the bottom of the workbench.
|
||||
import { t } from "$lib/i18n";
|
||||
import type { ViewMode } from "./ViewModes.svelte";
|
||||
|
||||
let { message, watchMode, source }: { message: string; watchMode: string | null; source: boolean } = $props();
|
||||
// `view` is the view of the active text document, or null for other tabs.
|
||||
let { message, watchMode, view }: { message: string; watchMode: string | null; view: ViewMode | null } = $props();
|
||||
</script>
|
||||
|
||||
<footer class="status">
|
||||
@@ -10,7 +12,7 @@
|
||||
{#if watchMode}
|
||||
<span>{watchMode} watch</span>
|
||||
{/if}
|
||||
<span>{source ? $t("IDE") : $t("Writer")}</span>
|
||||
{#if view}<span>{view === "read" ? $t("Read") : view === "source" ? $t("Source") : $t("Write")}</span>{/if}
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
@@ -26,7 +28,10 @@
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* The message takes the free space, so the other items stay at the right. */
|
||||
.status :first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
color: var(--rs-text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<script lang="ts" module>
|
||||
/** The view of a document pane. Split is a separate toggle beside Write or Source. */
|
||||
export type ViewMode = "write" | "source" | "read";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
// The view control of a document pane: Write, Source, and Read in one radio group, then the Split toggle.
|
||||
// All choices stay visible. Narrow panes show only the icons.
|
||||
import { t } from "$lib/i18n";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import type { IconName } from "$lib/ui/IconButton.svelte";
|
||||
import { attachTooltip } from "$lib/ui/tooltip";
|
||||
import { commandShortcut } from "./workbenchKeys";
|
||||
|
||||
type Option = { value: ViewMode; label: string; icon: IconName; shortcut: string };
|
||||
type Props = {
|
||||
view: ViewMode;
|
||||
split: boolean;
|
||||
/** Markdown files have Read and Split. Other text files have only Write and Source. */
|
||||
readable: boolean;
|
||||
onView: (view: ViewMode) => void;
|
||||
onSplit: (split: boolean) => void;
|
||||
};
|
||||
let { view, split, readable, onView, onSplit }: Props = $props();
|
||||
let group: HTMLDivElement;
|
||||
|
||||
const options: Option[] = $derived([
|
||||
{ value: "write", label: $t("Write"), icon: "pen", shortcut: commandShortcut("toggle-layout") },
|
||||
{ value: "source", label: $t("Source"), icon: "code", shortcut: commandShortcut("toggle-layout") },
|
||||
...(readable ? [{ value: "read" as const, label: $t("Read"), icon: "book-open" as const, shortcut: commandShortcut("toggle-reading") }] : []),
|
||||
]);
|
||||
|
||||
function tooltip(node: HTMLElement, text: string) {
|
||||
let current = text;
|
||||
const dispose = attachTooltip(node, () => current);
|
||||
return { update(value: string) { current = value; }, destroy: dispose };
|
||||
}
|
||||
|
||||
// Arrow keys move the choice, as in each radio group. The group has one Tab stop.
|
||||
function keydown(event: KeyboardEvent, index: number) {
|
||||
const last = options.length - 1;
|
||||
const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? (index + 1) % options.length
|
||||
: event.key === "ArrowLeft" || event.key === "ArrowUp" ? (index + last) % options.length
|
||||
: event.key === "Home" ? 0 : event.key === "End" ? last : -1;
|
||||
if (next < 0) return;
|
||||
event.preventDefault();
|
||||
onView(options[next].value);
|
||||
group.querySelectorAll<HTMLButtonElement>("[role=radio]")[next]?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="view-modes" role="radiogroup" aria-label={$t("View")} bind:this={group}>
|
||||
{#each options as option, index (option.value)}
|
||||
<button type="button" role="radio" aria-checked={option.value === view} aria-label={option.label}
|
||||
tabindex={option.value === view ? 0 : -1}
|
||||
use:tooltip={`${option.label} (${option.shortcut})`}
|
||||
onclick={() => onView(option.value)} onkeydown={event => keydown(event, index)}>
|
||||
<Icon icon={option.icon} /><span class="label" aria-hidden="true">{option.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{#if readable}
|
||||
<button type="button" class="split" aria-pressed={split} aria-label={$t("Split")} use:tooltip={$t("Split: Read beside the editor")} onclick={() => onSplit(!split)}>
|
||||
<Icon icon="split" /><span class="label" aria-hidden="true">{$t("Split")}</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.view-modes {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
gap: 2px;
|
||||
padding: 2px;
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
}
|
||||
|
||||
button {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 26px;
|
||||
min-width: 28px;
|
||||
padding: 0 8px;
|
||||
border: 0;
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: transparent;
|
||||
color: var(--rs-text-dim);
|
||||
font: 12px var(--rs-font-ui);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
button :global(svg) { width: 16px; height: 16px; flex-shrink: 0; }
|
||||
|
||||
/* Hover gets only a fill. The current choice also gets the selection fill and an accent bar. */
|
||||
button:hover { background: var(--rs-bg-active); color: var(--rs-text-strong); }
|
||||
button[aria-checked="true"], button[aria-pressed="true"] {
|
||||
background: var(--rs-item-selection-bg);
|
||||
color: var(--rs-text-strong);
|
||||
box-shadow: inset 0 -2px 0 var(--rs-accent);
|
||||
}
|
||||
|
||||
.split { height: 32px; border: 1px solid var(--rs-border); }
|
||||
|
||||
@container (max-width: 560px) {
|
||||
.label { display: none; }
|
||||
button { padding: 0 6px; }
|
||||
}
|
||||
</style>
|
||||
@@ -9,7 +9,8 @@
|
||||
import type { MenuLink } from "$lib/editor/linkMenu";
|
||||
import { WorkspaceSession } from "$lib/workspace/session.svelte";
|
||||
import { retainEditorStates } from "$lib/editor/editorStates";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane } from "$lib/workspace/documentPanes";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView } from "$lib/workspace/documentPanes";
|
||||
import type { ViewMode } from "./ViewModes.svelte";
|
||||
import { selectedEditorText } from "$lib/editor/selection";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import type { Contributions } from "$lib/plugins/contracts";
|
||||
@@ -146,7 +147,8 @@
|
||||
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
|
||||
let terminalOpen = $state(false);
|
||||
let documentPanes = $state(initialDocumentPanes());
|
||||
const reading = $derived(documentPanes.panes.find(pane => pane.id === documentPanes.active)?.reading ?? false);
|
||||
const activeDocumentPane = $derived(documentPanes.panes.find(pane => pane.id === documentPanes.active));
|
||||
const reading = $derived(activeDocumentPane?.reading ?? false);
|
||||
let quickOpen = $state(false);
|
||||
let palette = $state(false);
|
||||
/** The commands of the palette: the app commands that apply here, then the plugin commands. */
|
||||
@@ -362,7 +364,10 @@
|
||||
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 isSource = $derived(view === "Source");
|
||||
const readable = $derived(buffer?.kind === "text" && isMarkdownPath(buffer.relPath));
|
||||
// The status bar names the view of the active pane. Split shows the editor view.
|
||||
const viewMode: ViewMode = $derived(reading && readable ? "read" : isSource ? "source" : "write");
|
||||
const outlineItems = $derived(
|
||||
buffer && buffer.kind === "text" ? buildOutline(buffer.relPath, buffer.contents) : [],
|
||||
);
|
||||
@@ -372,12 +377,26 @@
|
||||
}
|
||||
|
||||
function toggleChrome() {
|
||||
const next = view === "Writing" ? "Ide" : "Writing";
|
||||
const next = view === "Writing" ? "Source" : "Writing";
|
||||
setReading(false);
|
||||
applyChrome(next);
|
||||
documents?.setChrome(next);
|
||||
}
|
||||
|
||||
/** Show Write, Source, or Read in a pane. Write and Source keep a Split view. */
|
||||
function setDocumentView(paneId: string, next: ViewMode) {
|
||||
focusDocumentPane(paneId);
|
||||
if (next === "read") { setReading(true, paneId); return; }
|
||||
setReading(false, paneId);
|
||||
const chrome = next === "source" ? "Source" : "Writing";
|
||||
if (chrome !== view) { applyChrome(chrome); documents?.setChrome(chrome); }
|
||||
}
|
||||
|
||||
function setSplitView(paneId: string, split: boolean) {
|
||||
focusDocumentPane(paneId);
|
||||
documentPanes = splitDocumentView(documentPanes, paneId, split);
|
||||
}
|
||||
|
||||
function toggleTerminal() {
|
||||
if (!terminalEnabled) return;
|
||||
terminalOpen = !terminalOpen;
|
||||
@@ -510,7 +529,7 @@
|
||||
focusLine = null;
|
||||
documents?.select(relPath);
|
||||
focusDocumentPane(documentPanes.active, true);
|
||||
status = documents?.active?.kind === "empty" ? $t("New tab") : relPath;
|
||||
status = documents?.active?.kind === "empty" ? $t("New tab") : "";
|
||||
}
|
||||
|
||||
function selectWorkingTab(path: string) {
|
||||
@@ -660,8 +679,13 @@
|
||||
if (tab.kind === "text" && isMarkdownPath(tab.relPath)) {
|
||||
items.push(
|
||||
{ label: $t("Save as template"), icon: "copy", run: () => { void saveTemplate({ name: tab.name, rel_path: tab.relPath, kind: "file" }); } },
|
||||
{ label: reading ? $t("Editing view") : $t("Reading view"), icon: "book", run: () => activeEditor()?.toggleReadingView() },
|
||||
{ label: isIde ? $t("Writing mode") : $t("Source mode"), icon: "code", run: toggleChrome },
|
||||
{ label: $t("View"), icon: "book", children: [
|
||||
{ label: $t("Write"), icon: "paragraph", radio: true, checked: viewMode === "write", run: () => setDocumentView(documentPanes.active, "write") },
|
||||
{ label: $t("Source"), icon: "code", radio: true, checked: viewMode === "source", run: () => setDocumentView(documentPanes.active, "source") },
|
||||
{ label: $t("Read"), icon: "book", radio: true, checked: viewMode === "read", run: () => setDocumentView(documentPanes.active, "read") },
|
||||
{ separator: true },
|
||||
{ label: $t("Split"), icon: "split-right", checked: activeDocumentPane?.split === true && !reading, run: () => setSplitView(documentPanes.active, !(activeDocumentPane?.split && !reading)) },
|
||||
] },
|
||||
);
|
||||
}
|
||||
items.push({ separator: true },
|
||||
@@ -684,12 +708,12 @@
|
||||
try {
|
||||
const open = current.buffers.find(tab => tab.relPath === entry.rel_path);
|
||||
if (!line && !(open && open.contents !== open.saved) && await openPluginDocument(entry.rel_path, () => documents === current && !switching)) {
|
||||
status = entry.rel_path; error = null; return;
|
||||
status = ""; error = null; return;
|
||||
}
|
||||
await current.open(entry, target);
|
||||
if (documents !== current) return;
|
||||
pluginEditorActive.set(false);
|
||||
status = entry.rel_path;
|
||||
status = "";
|
||||
error = null;
|
||||
focusLine = null;
|
||||
if (line) {
|
||||
@@ -882,6 +906,7 @@
|
||||
case "open-workspace": void chooseWorkspace(); return true;
|
||||
case "new-file": void newFile(); return true;
|
||||
case "toggle-layout": if (!editorPluginVisible) toggleChrome(); return true;
|
||||
case "toggle-reading": if (!editorPluginVisible && readable) setReading(!reading); return true;
|
||||
case "toggle-terminal": if (!terminalEnabled) return false; toggleTerminal(); return true;
|
||||
case "close-tab":
|
||||
if (editorPluginVisible) { if (activeTabPath) void closeTab(activeTabPath); }
|
||||
@@ -1281,8 +1306,8 @@
|
||||
defaultBrowser: target => openUrl(target),
|
||||
workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id),
|
||||
})}
|
||||
onToggleReading={(pane) => setReading(!pane.reading, pane.id)}
|
||||
onToggleChrome={(pane) => { focusDocumentPane(pane.id); toggleChrome(); }}
|
||||
onView={(pane, next) => setDocumentView(pane.id, next)}
|
||||
onSplitView={(pane, next) => setSplitView(pane.id, next)}
|
||||
onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
|
||||
/>
|
||||
{#if terminalContribution && terminalStarted}
|
||||
@@ -1329,7 +1354,7 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<StatusBar message={error ?? status} watchMode={workspace?.watch_mode ?? null} source={isIde} />
|
||||
<StatusBar message={error ?? status} watchMode={workspace?.watch_mode ?? null} view={buffer?.kind === "text" ? viewMode : null} />
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { keys, shortcutLabel } from "../ui/shortcuts.ts";
|
||||
|
||||
/** The commands of the workbench shortcuts. Workbench.svelte runs them. */
|
||||
export type WorkbenchCommand =
|
||||
| "command-palette" | "quick-open" | "new-tab" | "search-workspace" | "save" | "open-workspace" | "new-file" | "toggle-layout"
|
||||
| "command-palette" | "quick-open" | "new-tab" | "search-workspace" | "save" | "open-workspace" | "new-file" | "toggle-layout" | "toggle-reading"
|
||||
| "toggle-terminal" | "close-tab" | "toggle-sidebar" | "rename" | "next-tab" | "previous-tab" | "settings" | "help";
|
||||
|
||||
/**
|
||||
@@ -32,6 +32,7 @@ export const workbenchKeys: WorkbenchKey[] = [
|
||||
{ key: "s", mod: true, command: "save" },
|
||||
{ key: "o", mod: true, command: "open-workspace" },
|
||||
{ key: "n", mod: true, command: "new-file" },
|
||||
{ key: "e", mod: true, shift: true, command: "toggle-reading" },
|
||||
{ key: "e", mod: true, command: "toggle-layout" },
|
||||
{ key: "`", mod: true, command: "toggle-terminal" },
|
||||
{ key: "w", mod: true, command: "close-tab" },
|
||||
@@ -57,7 +58,8 @@ export const COMMAND_LABELS: Record<WorkbenchCommand, string> = {
|
||||
save: message("Save the active file"),
|
||||
"open-workspace": message("Open a workspace"),
|
||||
"new-file": message("New file"),
|
||||
"toggle-layout": message("Switch between writing and source editing"),
|
||||
"toggle-layout": message("Switch between Write and Source"),
|
||||
"toggle-reading": message("Switch between Read and the editor"),
|
||||
"toggle-terminal": message("Show or hide the terminal"),
|
||||
"close-tab": message("Close the tab"),
|
||||
"toggle-sidebar": message("Show or hide the side pane"),
|
||||
|
||||
Reference in New Issue
Block a user