Show different tabs side by side in split view

Each tab menu has "Open to the right". It shows the tab in a new pane to
the right of the active pane. A pane shows a document or a plugin tab,
for example a browser tab.

- A plugin view stays in the plugin layer above the panes, so a move
  between panes does not mount it again.
- A browser tab that covers the area moves to the left pane when a tab
  opens beside it. The last pane gives its plugin tab the whole area.
- The "Split" toggle of a document is now "Read beside".

Card 565874b2.
This commit is contained in:
Knotty Wyvern
2026-11-10 06:40:44 -07:00
parent d19bb6a1f0
commit 61976191d0
22 changed files with 473 additions and 116 deletions
+17
View File
@@ -1155,3 +1155,20 @@ Update 2026-10-29: The native Terminal feature keeps the 65% cap on `--rs-select
- Evidence: `tests/smoke/features/pdf.smoke.mjs` and `tests/unit/features/pdf.spec.ts`.
- Replaces / replaced by: The one-page rule and the zoom text of [UI-059](#ui-059--the-pdf-toolbar-on-shared-controls).
- Limits: Only the pages near the visible area have a drawing. Until the viewer reads the size of a page, the page has the size of the first page. Browser checks use desktop service mocks. Native desktop acceptance remains open.
### UI-064 — Split view shows different tabs
- Type: Rule change
- Date: 2026-11-10
- Status: Implemented for user review
- Decision source: Card 565874b2 reports that split view shows only the same document side by side. The user expects different documents side by side, also with a web browser.
- Previous rule: [UI-021](#ui-021--workspace-links-in-document-panes). Only a file tree item or a workspace link opened a document to the right. Document panes held only documents. A plugin tab, for example a browser tab, covered the whole document area. The **Split** toggle showed Read beside the editor of the same document.
- New rule: Each tab menu has **Open to the right**. It shows the tab in a new pane to the right of the active pane. A pane shows a document or a plugin tab. A tab shows in one pane at most, so the item is unavailable for a visible tab. A tab that the user selects, or a file that the user opens, replaces the content of the active pane. The replaced tab stays open. A plugin tab that covers the area moves to the active pane when a tab opens beside it. When one pane is left, its plugin tab covers the area again. A plugin pane has a bar with its title and **Close split**. A document pane beside other panes shows the full path in its bar. The **Split** toggle is now **Read beside**.
- Reason: "Split" named two different things. Users compare a note with a different note or with a web page.
- Scope: Document panes, plugin editor tabs, the tab menu, and the view control.
- Shared implementation: `src/lib/workspace/documentPanes.ts`, `src/lib/workspace/splitLayout.ts` (`stackLayout`, `splitSibling`), `src/lib/layout/DocumentArea.svelte`, and `src/lib/layout/Workbench.svelte`. A plugin view stays in the plugin layer above the panes, so a move between panes does not mount it again.
- Exceptions: **Split right** and **Split down** in the menu of a browser tab still open a copy of the page. In a pane, the copy opens beside that pane.
- Narrow layout: An area of 640 pixels or less shows the panes one above the other, in the same order. The area does not scroll. Each pane keeps its own scroll bar.
- Evidence: `tests/smoke/layout/mixedSplits.smoke.mjs`, `tests/smoke/layout/splits.smoke.mjs`, and `tests/unit/layout/documentPanes.spec.ts`.
- Replaces / replaced by: The document-only panes of [UI-021](#ui-021--workspace-links-in-document-panes), and the name **Split** of [UI-049](#ui-049--one-view-control-and-one-file-name).
- Limits: Panes have equal sizes. A drag cannot move a tab into a pane. Browser checks use desktop service mocks. Native desktop acceptance remains open.
+3 -3
View File
@@ -24,11 +24,11 @@ Select an image, then right-click it or press Shift+F10 for these actions:
- **Copy path** and **Show in Explorer**, for workspace images
**Remove image**, or the Delete key, removes the image link from the note. It does not delete the file. Undo restores the link.
Zoom works in Write, Read, and Split. It can fit the image or magnify it. Press Escape to close it.
Zoom works in Write, Read, and Read beside. It can fit the image or magnify it. Press Escape to close it.
## Read diagrams and document properties
Write, Read, and Split show wiki links, note callouts, and Mermaid diagrams.
Write, Read, and Read beside show wiki links, note callouts, and Mermaid diagrams.
RuneStone renders Mermaid diagrams locally. If a diagram is not valid, RuneStone shows an error message and the diagram source.
Read shows frontmatter in a collapsed **Properties** section.
@@ -97,7 +97,7 @@ Start a cell with `=` to make a formula. Columns use letters A, B, … AA. Row 1
| Functions | SUM, AVERAGE, MIN, MAX, COUNT, ABS, and ROUND |
Functions that take a range ignore text and blank cells. Arithmetic uses zero for a blank cell.
Results update in Write, Read, and Split. Select a result to edit its formula. Enter saves the formula, and Tab moves to the next cell.
Results update in Write, Read, and Read beside. Select a result to edit its formula. Enter saves the formula, and Tab moves to the next cell.
The **Formulas** control below each table explains the syntax. The active cell shows its address.
A formula that is not valid, a missing cell, or a circular reference shows an error label.
+1 -1
View File
@@ -222,7 +222,7 @@ Decisions: [UI-009](design-decisions.md#ui-009--character-theme-appearances), [U
- The app image fills the work area below the titlebar, including new tabs and document views. It stays fixed while content scrolls.
- Sidebars use `--rs-image-sidebar-bg` (82% tint). Editor surfaces use `--rs-image-editor-bg` (90% tint). Without an image, both are opaque.
- Write, Source, Read, and Split share the editor surface. CodeMirror layers stay transparent above it.
- Write, Source, Read, and Read beside share the editor surface. CodeMirror layers stay transparent above it.
- Code blocks in Write and Read use `--rs-code-block-bg`.
- Hovered rows and controls in the work area, hovered menu rows, and the workspace button use `--rs-hover-bg`. With an image, it is a 6% veil of the strong text color. The image stays visible, and the hover shows over light and dark image areas. Dialogs and Settings keep opaque fills.
- New-tab buttons use `--rs-image-control-bg` and `--rs-image-control-hover-bg`. Their tint keeps labels readable while the image stays visible. The new-tab screen shows only its action buttons, with icons, labels, and shortcuts.
+14 -2
View File
@@ -75,14 +75,14 @@ On macOS and Linux, you can still open, edit, rename, and delete existing files
## Edit documents
Each document pane has one view control with three choices, and a **Split** button:
Each document pane has one view control with three choices, and a **Read beside** button:
| Choice | Shows |
| --- | --- |
| **Write** | Formatted Markdown. The active line shows its Markdown source. |
| **Source** | The plain source with line numbers and syntax colors |
| **Read** | The rendered document, without editing. Markdown files only. |
| **Split** | Read beside Write or Source. Narrow panes stack the two views. Select **Split** again to close it. Markdown files only. |
| **Read beside** | Read beside Write or Source. Narrow panes stack the two views. Select **Read beside** again to close it. Markdown files only. |
Press Ctrl+E to switch between Write and Source. Press Ctrl+Shift+E to switch between Read and the editor. The tab menu has the same choices under **View**.
The control shows icons only. Hover over an icon, or focus it with the keyboard, to see its name and shortcut. The arrow keys move the choice.
@@ -184,6 +184,18 @@ If the move fails, the source tab stays open.
When you start RuneStone again, it opens the document tabs of the workspace. It keeps their order, pins, and active tab.
This includes PDF tabs and plugin tabs that show a file. RuneStone reads the contents again from disk. Missing files do not stop the other tabs from opening.
### Show tabs side by side
1. Right-click a tab that is not visible.
2. Select **Open to the right**.
The tab opens in a new pane to the right of the active pane. A pane shows a document or a plugin tab, for example a browser tab. A tab shows in one pane at a time.
- Click a pane to make its tab the active tab. A tab that you select, or a file that you open, replaces the content of the active pane. The replaced tab stays open.
- A pane beside other panes names its file in the bar above the document. Select **Close split** in that bar to close the pane. The tab stays open.
- A browser tab that fills the area moves to the left pane when a tab opens to the right. When one pane is left, its browser tab fills the area again.
- The file menu of the file tree and the link menu also have **Open to the right**. In a narrow window, the panes show one above the other.
## Save your work
Auto-save is on by default. It saves changed files every 5 seconds, also in background tabs. RuneStone does not write unchanged files.
+5 -5
View File
@@ -1020,10 +1020,10 @@ export const messageRows: [string, string, string, string][] = [
"阅读"
],
[
"Split",
"Diviser",
"分割",
"分栏"
"Read beside",
"Lire à côté",
"横に閲覧",
"并排阅读"
],
[
"Editor",
@@ -3376,7 +3376,7 @@ export const messageRows: [string, string, string, string][] = [
["Show the file name above each Markdown note in Write and Read.", "Afficher le nom du fichier au-dessus de chaque note Markdown dans Écrire et Lire.", "「書く」と「閲覧」で、各 Markdown ノートの上にファイル名を表示します。", "在“写作”和“阅读”中,在每篇 Markdown 笔记上方显示文件名。"],
["Source", "Source", "ソース", "源码"],
["View", "Affichage", "表示", "视图"],
["Split: Read beside the editor", "Diviser : Lire à côté de l’éditeur", "分割: エディターの横に閲覧を表示", "分栏:在编辑器旁显示阅读"],
["Read beside: show the Read view beside the editor", "Lire à côté : afficher Lire à côté de l’éditeur", "横に閲覧: エディターの横に閲覧を表示", "并排阅读:在编辑器旁显示阅读"],
["Switch between Write and Source", "Alterner entre Écrire et Source", "「書く」と「ソース」を切り替え", "在写作和源码之间切换"],
["Switch between Read and the editor", "Alterner entre Lire et l’éditeur", "「閲覧」とエディターを切り替え", "在阅读和编辑器之间切换"],
["Unsaved", "Non enregistré", "未保存", "未保存"],
+72 -38
View File
@@ -1,26 +1,32 @@
<script lang="ts">
// The document area: plugin editor panes over the document panes, with the save conflict banner of each document.
// The document area: the panes of documents and plugin editor views, with the save conflict banner of each document.
// A plugin view stays in the plugin layer above the document panes, so that a move between panes does not mount it again.
// Over the whole area, the layer shows the focused plugin view and its plugin split. In a pane, the view covers its pane.
import type { ComponentProps } from "svelte";
import { t } from "$lib/i18n";
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
import { pluginEditors, pluginView, selectPluginEditor } from "$lib/plugins/external";
import { pluginEditors, pluginView, selectPluginEditor, type OpenPluginView } from "$lib/plugins/external";
import type { Documents } from "$lib/workspace/documents.svelte";
import type { OpenBuffer } from "$lib/workspace/types";
import EditorPane from "./EditorPane.svelte";
import Icon from "$lib/ui/Icon.svelte";
import IconButton from "$lib/ui/IconButton.svelte";
import { paneBounds, stackLayout, type SplitLayout } from "$lib/workspace/splitLayout";
import type { ViewMode } from "./ViewModes.svelte";
import TabBar from "./TabBar.svelte";
type EditorProps = ComponentProps<typeof EditorPane>;
type DocumentView = { id: string; reading: boolean; split: boolean; buffer: OpenBuffer | null; bounds: { width: number } };
type DocumentView = { id: string; reading: boolean; split: boolean; buffer: OpenBuffer | null; pluginKey: string | null };
type Bounds = { left: number; top: number; width: number; height: number };
type Props = {
editorPluginVisible: boolean;
/** The focused plugin view covers the whole area. */
pluginCover: boolean;
split: boolean;
pluginBounds: Record<string, Bounds | undefined>;
tabBar: ComponentProps<typeof TabBar>;
pluginPaneComponents: Record<string, PluginEditor | undefined>;
documentViews: DocumentView[];
layout: SplitLayout;
activePane: string;
paneComponents: Record<string, EditorPane | undefined>;
documents: Documents | null;
@@ -46,37 +52,36 @@
onCursor: (pane: DocumentView, line: number, column: number) => void;
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
};
let { editorPluginVisible, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, activePane, paneComponents = $bindable(),
let { pluginCover, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, layout, activePane, paneComponents = $bindable(),
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onCursor, onOpenLink }: Props = $props();
// A narrow area shows the panes one above the other, in the same order.
let width = $state(0);
const stacked = $derived(width > 0 && width <= 640);
const bounds = $derived(paneBounds(stacked ? stackLayout(layout) : layout));
const hosts = $derived(new Map(documentViews.flatMap(pane => pane.pluginKey ? [[pane.pluginKey, pane.id] as const] : [])));
const several = $derived(documentViews.length > 1);
function focusPlugin(view: OpenPluginView, host: string | undefined) {
if (host) onFocusPane(host);
else if ($pluginView?.key !== view.key) selectPluginEditor(view);
}
</script>
<main class="center">
<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 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 split && bounds}
<TabBar {...tabBar} tabs={tabBar.tabs.filter(tab => tab.id === pane.key)} />
{/if}
<PluginEditor bind:this={pluginPaneComponents[pane.key]} view={pane} />
</div>
{/each}
</div>
<div class="editor-host" class:plugin-covered={editorPluginVisible}>
<div class="document-panes" class:split={documentViews.length > 1}>
<main class="center" bind:clientWidth={width}>
<div class="editor-host" class:plugin-covered={pluginCover}>
<div class="document-panes" class:split={several}>
{#each documentViews as pane (pane.id)}
{@const box = bounds[pane.id]}
<!-- svelte-ignore a11y_no_static_element_interactions (Focus identifies the document for shared commands.) -->
<div class="document-pane" class:focused={activePane === pane.id}
<div class="document-pane" class:focused={activePane === pane.id} class:edge-left={(box?.left ?? 0) > 0} class:edge-top={(box?.top ?? 0) > 0}
data-document-pane={pane.id} data-document-path={pane.buffer?.relPath ?? ""}
style:--pane-weight={pane.bounds.width}
style:left={`${box?.left ?? 0}%`} style:top={`${box?.top ?? 0}%`}
style:width={`${box?.width ?? 100}%`} style:height={`${box?.height ?? 100}%`}
onpointerdowncapture={() => onFocusPane(pane.id)}
onfocusin={() => onFocusPane(pane.id)}>
<!-- A pane with a plugin view stays empty. The plugin layer shows the view over it. -->
{#if !pane.pluginKey}
{#if pane.buffer?.diskError}
<div class="conflict" role="alert"><Icon icon="alert" /><span>{pane.buffer.diskError}</span><button class="primary" onclick={() => void documents?.refresh()}>{$t("Retry")}</button><button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button></div>
{:else if pane.buffer?.diskContents != null}
@@ -94,7 +99,7 @@
bind:this={paneComponents[pane.id]}
{tabs}
active={activePane === pane.id}
onCloseSplit={documentViews.length > 1 ? () => onCloseSplit(pane.id) : undefined}
onCloseSplit={several ? () => onCloseSplit(pane.id) : undefined}
{hasWorkspace}
{onOpenWorkspace}
{onNewFile}
@@ -117,10 +122,36 @@
onCursor={(line, column) => onCursor(pane, line, column)}
onOpenLink={(kind, target) => onOpenLink(pane, kind, target)}
/>
{/if}
</div>
{/each}
</div>
</div>
<div class="plugin-panes">
{#each $pluginEditors as view (view.key)}
{@const host = pluginCover ? undefined : hosts.get(view.key)}
{@const box = pluginCover ? pluginBounds[view.key] : host ? bounds[host] : undefined}
<!-- svelte-ignore a11y_no_static_element_interactions (Focus selects the pane that owns the input.) -->
<div class="plugin-pane" class:inactive={!box} class:split={pluginCover && split} class:embedded={!!host}
class:focused={host ? activePane === host : $pluginView?.key === view.key}
class:edge-left={!!host && (box?.left ?? 0) > 0} class:edge-top={!!host && (box?.top ?? 0) > 0}
data-plugin-pane={view.key}
style:left={`${box?.left ?? 0}%`} style:top={`${box?.top ?? 0}%`}
style:width={`${box?.width ?? 100}%`} style:height={`${box?.height ?? 100}%`}
onfocusin={() => focusPlugin(view, host)}
onpointerdowncapture={() => focusPlugin(view, host)}>
{#if pluginCover && split && box}
<TabBar {...tabBar} tabs={tabBar.tabs.filter(tab => tab.id === view.key)} />
{:else if host && several}
<div class="pane-bar">
<span class="pane-title" title={view.title}>{view.title}</span>
<IconButton icon="close" label={$t("Close split")} onclick={() => onCloseSplit(host)} />
</div>
{/if}
<PluginEditor bind:this={pluginPaneComponents[view.key]} {view} />
</div>
{/each}
</div>
</main>
<style>
@@ -155,19 +186,22 @@
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); }
/* Each pane has its place in the split layout. A pane beside or below another pane has a border on that edge. */
.document-panes { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.document-pane { position: absolute; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; box-sizing: border-box; }
.edge-left { border-left: 1px solid var(--rs-border); }
.edge-top { border-top: 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; }
.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; }
/* The plugin layer covers the area, but only its visible panes take the pointer. */
.plugin-panes { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.plugin-pane { position: absolute; display: flex; flex-direction: column; min-width: 0; min-height: 0; box-sizing: border-box; pointer-events: auto; }
.plugin-pane.embedded { background: var(--rs-bg); }
.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; }
.plugin-pane.inactive { display: none; }
/* The bar of a plugin view in a pane matches the chrome bar of a document pane. */
.pane-bar { display: flex; align-items: center; gap: 8px; min-height: 34px; flex: 0 0 auto; padding: 0 10px; background: var(--rs-bg); border-bottom: 1px solid var(--rs-border); color: var(--rs-text-dim); }
.plugin-pane.focused .pane-bar { background: var(--rs-bg-active); }
.pane-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
</style>
+3 -1
View File
@@ -147,7 +147,9 @@
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(" / ") : "");
// Beside other panes, the breadcrumb also names the file, because the tab bar names only the file of the active pane.
const folder = $derived(!buffer ? "" : onCloseSplit ? buffer.relPath.split("/").join(" / ")
: buffer.relPath.includes("/") ? buffer.relPath.slice(0, buffer.relPath.lastIndexOf("/")).split("/").join(" / ") : "");
</script>
{#if !buffer || buffer.kind === "empty"}
+4 -4
View File
@@ -1,10 +1,10 @@
<script lang="ts" module>
/** The view of a document pane. Split is a separate toggle beside Write or Source. */
/** The view of a document pane. Read beside 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.
// The view control of a document pane: Write, Source, and Read in one radio group, then the Read beside toggle.
// All choices stay visible. Narrow panes show only the icons.
import { t } from "$lib/i18n";
import Icon from "$lib/ui/Icon.svelte";
@@ -16,7 +16,7 @@
type Props = {
view: ViewMode;
split: boolean;
/** Markdown files have Read and Split. Other text files have only Write and Source. */
/** Markdown files have Read and Read beside. Other text files have only Write and Source. */
readable: boolean;
onView: (view: ViewMode) => void;
onSplit: (split: boolean) => void;
@@ -60,7 +60,7 @@
{/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)}>
<button type="button" class="split" aria-pressed={split} aria-label={$t("Read beside")} use:tooltip={$t("Read beside: show the Read view beside the editor")} onclick={() => onSplit(!split)}>
<Icon icon="split" />
</button>
{/if}
+94 -15
View File
@@ -6,13 +6,14 @@
import type PluginEditor from "$lib/plugins/PluginEditor.svelte";
import { featureOfOwner } from "$lib/features/catalog";
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup, pluginTools, installedPlugins, runPluginCommand } from "$lib/plugins/external";
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
import { containsPane, paneBounds, splitSibling } 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, onDestroy, tick, untrack } from "svelte";
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, splitDocumentView } from "$lib/workspace/documentPanes";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView,
paneOf, showInActivePane, splitWithContent, releaseSolePlugin, type PaneContent } from "$lib/workspace/documentPanes";
import type { ViewMode } from "./ViewModes.svelte";
import { selectedEditorText } from "$lib/editor/selection";
import { pluginHost } from "$lib/plugins/registry";
@@ -229,7 +230,9 @@
}, () => {
if (documents !== next) return;
const selected = next.active;
documentPanes = syncDocumentPanes(documentPanes, next.buffers.map(tab => tab.id), selected?.id ?? null);
// While a plugin view has the focus, a document change does not replace the content of a pane.
const pluginFocused = $pluginEditorActive && $pluginView?.placement === "editor";
documentPanes = syncDocumentPanes(documentPanes, next.buffers.map(tab => tab.id), pluginFocused ? null : selected?.id ?? null);
if (selected) view = selected.chromeOverride ?? selected.chrome;
});
return next;
@@ -238,8 +241,8 @@
onDestroy(() => retainEditorStates([]));
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);
return documentPanes.panes.map(pane => ({ ...pane, buffer: tabs.find(tab => tab.id === pane.documentId) ?? null }))
.sort((a, b) => bounds[a.id].left - bounds[b.id].left || bounds[a.id].top - bounds[b.id].top);
});
function setReading(next: boolean, paneId = documentPanes.active) {
documentPanes = readDocumentPane(documentPanes, paneId, next);
@@ -249,6 +252,13 @@
if (!pane) return;
const tab = tabs.find(tab => tab.id === pane.documentId);
documentPanes = selectPane(documentPanes, paneId);
if (pane.pluginKey) {
const key = pane.pluginKey;
const view = $pluginEditors.find(view => view.key === key);
if (view && !($pluginEditorActive && $pluginView?.key === key)) selectPluginEditor(view);
if (focusEditor) void tick().then(() => { if (documentPanes.active === paneId) pluginPaneComponents[key]?.focus(); });
return;
}
pluginEditorActive.set(false);
if (tab && documents?.active?.id !== tab.id) { focusLine = null; documents?.select(tab.relPath); }
if (focusEditor) void tick().then(() => {
@@ -258,26 +268,90 @@
});
}
function closeSplit(paneId: string) {
documentPanes = closeDocumentPane(documentPanes, paneId);
focusDocumentPane(documentPanes.active, true);
const released = releaseSolePlugin(closeDocumentPane(documentPanes, paneId));
documentPanes = released.state;
// The last pane does not keep a plugin view. The view covers the area again.
const view = $pluginEditors.find(view => view.key === released.pluginKey);
if (view) {
selectPluginEditor(view);
void tick().then(() => pluginPaneComponents[view.key]?.focus());
} else focusDocumentPane(documentPanes.active, true);
}
/** The plugin view that covers the document area moves into the active pane, so that a new pane can open beside it. */
function keepCoverInPane() {
if (coverKey) documentPanes = showInActivePane(documentPanes, { pluginKey: coverKey });
}
async function openToRight(file: TreeEntry, sourcePane: string) {
const current = documents;
const covered = sourcePane === documentPanes.active ? coverKey : null;
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 now = documentPanes.panes.find(pane => pane.id === sourcePane);
if (documents !== current || switching || documentPanes.active !== sourcePane || coverKey !== covered
|| now?.documentId !== source.documentId || now?.pluginKey !== source.pluginKey) return;
const target = current.buffers.find(tab => tab.relPath === file.rel_path);
if (!target) return;
keepCoverInPane();
documentPanes = splitDocumentPane(documentPanes, sourcePane, target.id, crypto.randomUUID());
focusDocumentPane(documentPanes.active, true);
}
function tabContent(tab: EditorTab): PaneContent {
return "plugin" in tab ? { pluginKey: tab.plugin.key } : { documentId: tab.buffer.id };
}
/** A visible tab is the plugin view over the area, or the content of a pane. */
function tabVisible(tab: EditorTab) {
if (coverKey) return "plugin" in tab && tab.plugin.key === coverKey;
return !!paneOf(documentPanes, tabContent(tab));
}
/** Show a tab in a new pane to the right of the active pane. The active pane keeps its content. */
function openTabToRight(tab: EditorTab) {
if (switching || tabVisible(tab)) return;
keepCoverInPane();
documentPanes = splitWithContent(documentPanes, documentPanes.active, tabContent(tab), crypto.randomUUID());
focusDocumentPane(documentPanes.active, true);
}
// Each focused plugin view that is not in a pane gets a pane when the area has several panes.
// A new view that a plugin opens beside its own view, for example a browser tab, opens beside the pane of that view.
const placedPlugins = new Set<string>();
$effect(() => {
const view = $pluginEditorActive && $pluginView?.placement === "editor" ? $pluginView : null;
const splits = $pluginSplits;
if (!view) return;
untrack(() => {
const fresh = !placedPlugins.has(view.key);
placedPlugins.add(view.key);
const shown = paneOf(documentPanes, { pluginKey: view.key });
if (shown) { documentPanes = selectPane(documentPanes, shown.id); return; }
if (documentPanes.panes.length < 2) return;
const group = fresh ? splits.find(tree => containsPane(tree, view.key)) : undefined;
const beside = group ? splitSibling(group, view.key) : null;
const source = beside ? paneOf(documentPanes, { pluginKey: beside.sibling }) : undefined;
documentPanes = source && beside
? splitWithContent(documentPanes, source.id, { pluginKey: view.key }, crypto.randomUUID(), beside.direction)
: showInActivePane(documentPanes, { pluginKey: view.key });
});
});
// The selected document is visible while no plugin view has the focus.
$effect(() => {
const selected = $pluginEditorActive && $pluginView?.placement === "editor" ? null : buffer?.id ?? null;
if (selected) untrack(() => { documentPanes = showInActivePane(documentPanes, { documentId: selected }); });
});
// A closed plugin view leaves its pane. The last pane does not keep a plugin view.
$effect(() => {
const keys = $pluginEditors.map(view => view.key);
untrack(() => {
for (const key of placedPlugins) if (!keys.includes(key)) placedPlugins.delete(key);
documentPanes = releaseSolePlugin(syncDocumentPanes(documentPanes, tabs.map(tab => tab.id), null, keys)).state;
});
});
let focusLine = $state<number | null>(null);
let dragging = $state<"left" | "right" | "bottom" | null>(null);
let centerStack: HTMLElement | undefined = $state();
// A focused plugin view is the active tab. It covers the area only when no pane shows it.
const editorPluginVisible = $derived($pluginView?.placement === "editor" && $pluginEditorActive);
const coverKey = $derived(editorPluginVisible && $pluginView && !paneOf(documentPanes, { pluginKey: $pluginView.key }) ? $pluginView.key : null);
type EditorTab = WorkbenchTab & ({ buffer: OpenBuffer } | { plugin: OpenPluginView });
let tabOrder = $state<string[]>([]);
const availableTabs = $derived<EditorTab[]>([
@@ -412,7 +486,7 @@
documents?.setChrome(next);
}
/** Show Write, Source, or Read in a pane. Write and Source keep a Split view. */
/** Show Write, Source, or Read in a pane. Write and Source keep Read beside. */
function setDocumentView(paneId: string, next: ViewMode) {
focusDocumentPane(paneId);
if (next === "read") { setReading(true, paneId); return; }
@@ -557,6 +631,8 @@
pluginEditorActive.set(false);
focusLine = null;
documents?.select(relPath);
const selected = documents?.active?.id;
if (selected) documentPanes = showInActivePane(documentPanes, { documentId: selected });
focusDocumentPane(documentPanes.active, true);
status = documents?.active?.kind === "empty" ? $t("New tab") : "";
}
@@ -585,9 +661,11 @@
}
function workingTabActions(item: WorkbenchTab): ActionMenuItem[] {
const tab = workingTabs.find(tab => tab.id === item.id);
const actions = tab && "plugin" in tab ? pluginTabActions(tab.plugin) : [];
if (actions.some(action => "label" in action && /(?:move|open).*new window/i.test(action.label))) return actions;
return tab ? [{ label: $t("Open in new window"), icon: "external", disabled: !desktop || !workspace, run: () => { void detachTab(tab); } }, ...actions] : [];
if (!tab) return [];
const actions = "plugin" in tab ? pluginTabActions(tab.plugin) : [];
const right: ActionMenuItem = { label: $t("Open to the right"), icon: "split-right", disabled: tabVisible(tab), run: () => openTabToRight(tab) };
if (actions.some(action => "label" in action && /(?:move|open).*new window/i.test(action.label))) return [right, ...actions];
return [right, { label: $t("Open in new window"), icon: "external", disabled: !desktop || !workspace, run: () => { void detachTab(tab); } }, ...actions];
}
async function detachTab(item: WorkbenchTab, keepSource = false) {
const tab = workingTabs.find(tab => tab.id === item.id);
@@ -722,7 +800,7 @@
{ 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)) },
{ label: $t("Read beside"), icon: "split-right", checked: activeDocumentPane?.split === true && !reading, run: () => setSplitView(documentPanes.active, !(activeDocumentPane?.split && !reading)) },
] },
);
}
@@ -1379,11 +1457,12 @@
<DocumentArea
bind:pluginPaneComponents
bind:paneComponents
{editorPluginVisible}
pluginCover={coverKey !== null}
split={!!activeSplit}
{pluginBounds}
tabBar={tabBarProps}
{documentViews}
layout={documentPanes.layout}
activePane={documentPanes.active}
{documents}
{tabs}
+73 -21
View File
@@ -1,30 +1,40 @@
import { paneBounds, removePane, splitPane, type SplitLayout } from "./splitLayout.ts";
/** `reading` shows only the Read view. `split` shows the Read view beside the editor. A pane never has both. */
export type DocumentPane = { id: string; documentId: string | null; reading: boolean; split: boolean };
/**
* A pane shows one document or one plugin editor view, for example a browser tab. A pane never shows both.
* `reading` shows only the Read view. `split` shows the Read view beside the editor. A pane never has both.
*/
export type DocumentPane = { id: string; documentId: string | null; pluginKey: string | null; reading: boolean; split: boolean };
export type DocumentPanes = { layout: SplitLayout; panes: DocumentPane[]; active: string };
/** The content of a pane: a document ID or the key of a plugin editor view. */
export type PaneContent = { documentId: string } | { pluginKey: string };
function emptyPane(id: string): DocumentPane {
return { id, documentId: null, pluginKey: null, reading: false, split: false };
}
function filled(id: string, content: PaneContent): DocumentPane {
return "documentId" in content ? { ...emptyPane(id), documentId: content.documentId } : { ...emptyPane(id), pluginKey: content.pluginKey };
}
export function initialDocumentPanes(): DocumentPanes {
return { layout: "document-main", panes: [{ id: "document-main", documentId: null, reading: false, split: false }], active: "document-main" };
return { layout: "document-main", panes: [emptyPane("document-main")], active: "document-main" };
}
export function selectPane(state: DocumentPanes, id: string): DocumentPanes {
return state.active === id || !state.panes.some(pane => pane.id === id) ? state : { ...state, active: id };
}
/** Tabs own documents. Panes keep only a reference and local viewing state. */
export function syncDocumentPanes(state: DocumentPanes, live: readonly string[], selected: string | null): DocumentPanes {
const ids = new Set(live);
let panes = state.panes.map(pane => pane.documentId && !ids.has(pane.documentId) ? { ...pane, documentId: null, reading: false, split: false } : pane);
let active = state.active;
if (selected && ids.has(selected)) {
const existing = panes.find(pane => pane.documentId === selected);
if (existing) active = existing.id;
else panes = panes.map(pane => pane.id === active ? { ...pane, documentId: selected } : pane);
/** The pane that shows the content, if a pane shows it. */
export function paneOf(state: DocumentPanes, content: PaneContent): DocumentPane | undefined {
return state.panes.find(pane => "documentId" in content ? pane.documentId === content.documentId : pane.pluginKey === content.pluginKey);
}
/** Remove the panes that became empty. The last pane always stays. */
function collapse(state: DocumentPanes, panes: DocumentPane[], active: string): DocumentPanes {
let layout = state.layout;
for (const pane of panes) {
if (pane.documentId === null && panes.length > 1) {
if (pane.documentId === null && pane.pluginKey === null && panes.length > 1) {
const next = removePane(layout, pane.id);
if (next !== null) { layout = next; panes = panes.filter(item => item.id !== pane.id); }
}
@@ -34,14 +44,45 @@ export function syncDocumentPanes(state: DocumentPanes, live: readonly string[],
return { layout, panes, active };
}
export function splitDocumentPane(state: DocumentPanes, source: string, documentId: string, paneId: string): DocumentPanes {
const existing = state.panes.find(pane => pane.documentId === documentId);
/**
* Tabs own documents. Panes keep only a reference and local viewing state.
* A selected document that no pane shows replaces the content of the active pane.
* Give `livePlugins` to also clear the panes of closed plugin views.
*/
export function syncDocumentPanes(state: DocumentPanes, live: readonly string[], selected: string | null, livePlugins?: readonly string[]): DocumentPanes {
const ids = new Set(live);
const plugins = livePlugins ? new Set(livePlugins) : null;
let panes = state.panes.map(pane => {
if (pane.documentId && !ids.has(pane.documentId)) return { ...pane, documentId: null, reading: false, split: false };
if (plugins && pane.pluginKey && !plugins.has(pane.pluginKey)) return { ...pane, pluginKey: null };
return pane;
});
let active = state.active;
if (selected && ids.has(selected)) {
const existing = panes.find(pane => pane.documentId === selected);
if (existing) active = existing.id;
else panes = panes.map(pane => pane.id === active ? { ...pane, documentId: selected, pluginKey: null } : pane);
}
return collapse(state, panes, active);
}
/** Show the content in the active pane. When a pane already shows it, that pane becomes active. */
export function showInActivePane(state: DocumentPanes, content: PaneContent): DocumentPanes {
const existing = paneOf(state, content);
if (existing) return selectPane(state, existing.id);
return { ...state, panes: state.panes.map(pane => pane.id === state.active ? filled(pane.id, content) : pane) };
}
/** Show the content in a new pane beside `source`. When a pane already shows it, that pane becomes active. */
export function splitWithContent(state: DocumentPanes, source: string, content: PaneContent, paneId: string, direction: "right" | "down" = "right"): DocumentPanes {
const existing = paneOf(state, content);
if (existing) return selectPane(state, existing.id);
if (!state.panes.some(pane => pane.id === source) || state.panes.some(pane => pane.id === paneId)) return state;
return {
layout: splitPane(state.layout, source, paneId, "right"),
panes: [...state.panes, { id: paneId, documentId, reading: false, split: false }], active: paneId,
};
return { layout: splitPane(state.layout, source, paneId, direction), panes: [...state.panes, filled(paneId, content)], active: paneId };
}
export function splitDocumentPane(state: DocumentPanes, source: string, documentId: string, paneId: string): DocumentPanes {
return splitWithContent(state, source, { documentId }, paneId);
}
export function closeDocumentPane(state: DocumentPanes, id: string): DocumentPanes {
@@ -50,15 +91,26 @@ export function closeDocumentPane(state: DocumentPanes, id: string): DocumentPan
if (layout === null) return state;
const bounds = paneBounds(state.layout);
const panes = state.panes.filter(pane => pane.id !== id);
const neighbor = [...panes].sort((a, b) => Math.abs(bounds[a.id].left - bounds[id].left) - Math.abs(bounds[b.id].left - bounds[id].left))[0];
const distance = (pane: DocumentPane) => Math.abs(bounds[pane.id].left - bounds[id].left) + Math.abs(bounds[pane.id].top - bounds[id].top);
const neighbor = [...panes].sort((a, b) => distance(a) - distance(b))[0];
return { layout, panes, active: state.active === id ? neighbor.id : state.active };
}
/**
* One pane shows a plugin view only beside other panes. When the last pane shows a plugin view,
* the pane becomes empty and the result names the view, so that the caller can show it over the whole area.
*/
export function releaseSolePlugin(state: DocumentPanes): { state: DocumentPanes; pluginKey: string | null } {
const [pane] = state.panes;
if (state.panes.length !== 1 || pane.pluginKey === null) return { state, pluginKey: null };
return { state: { ...state, panes: [{ ...pane, pluginKey: null }] }, pluginKey: pane.pluginKey };
}
export function readDocumentPane(state: DocumentPanes, id: string, reading: boolean): DocumentPanes {
return { ...state, panes: state.panes.map(pane => pane.id === id ? { ...pane, reading, split: reading ? false : pane.split } : pane) };
}
/** Show or hide the Read view beside the editor. Split ends the Read-only view. */
/** Show or hide the Read view beside the editor. Read beside ends the Read-only view. */
export function splitDocumentView(state: DocumentPanes, id: string, split: boolean): DocumentPanes {
return { ...state, panes: state.panes.map(pane => pane.id === id ? { ...pane, split, reading: split ? false : pane.reading } : pane) };
}
+14
View File
@@ -23,3 +23,17 @@ export function paneBounds(tree: SplitLayout, bounds: PaneBounds = { left: 0, to
else { a.height /= 2; b.height /= 2; b.top += a.height; }
return { ...paneBounds(tree.first, a), ...paneBounds(tree.second, b) };
}
/** The same panes in the same order, one above the other. A narrow area uses it. */
export function stackLayout(tree: SplitLayout): SplitLayout {
return typeof tree === "string" ? tree : { direction: "down", first: stackLayout(tree.first), second: stackLayout(tree.second) };
}
/** The direction of the split that put `key` beside a different pane, and the first pane on the other side. */
export function splitSibling(tree: SplitLayout, key: string): { direction: "right" | "down"; sibling: string } | null {
if (typeof tree === "string") return null;
const first = (node: SplitLayout): string => typeof node === "string" ? node : first(node.first);
if (tree.second === key) return { direction: tree.direction, sibling: first(tree.first) };
if (tree.first === key) return { direction: tree.direction, sibling: first(tree.second) };
return splitSibling(tree.first, key) ?? splitSibling(tree.second, key);
}
+2 -2
View File
@@ -80,11 +80,11 @@ export function settle(page) {
}
/**
* Choose "Write", "Source", or "Read" in the view control of a document pane, or toggle "Split" (src/lib/layout/ViewModes.svelte).
* Choose "Write", "Source", or "Read" in the view control of a document pane, or toggle "Read beside" (src/lib/layout/ViewModes.svelte).
* `scope` is the page, or a pane locator when the window shows more than one document pane.
*/
export async function chooseView(scope, name) {
if (name === "Split") return scope.locator(".chrome-bar").getByRole("button", { name: "Split", exact: true }).click();
if (name === "Read beside") return scope.locator(".chrome-bar").getByRole("button", { name: "Read beside", exact: true }).click();
return scope.getByRole("radiogroup", { name: "View", exact: true }).getByRole("radio", { name, exact: true }).click();
}
@@ -103,11 +103,11 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
assert.deepEqual(await background.boundingBox(), beforeScroll);
await page.screenshot({ path: `${output}/${theme}-reader.png` });
// Split shows the Write editor beside Read.
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await page.locator('.live-writer .cm-content').waitFor();
assert.equal(await style(page.locator('.live-writer .cm-editor').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.screenshot({ path: `${output}/${theme}-split.png` });
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await chooseView(page, 'Source');
await page.locator('.source-editor .cm-content').waitFor();
await page.screenshot({ path: `${output}/${theme}-ide.png` });
+1 -1
View File
@@ -62,7 +62,7 @@ await runSmoke("find/typing", async ({ page }) => {
await page.locator(".md-page > .reading").focus();
}, reading);
await chooseView(page, "Source");
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await typing("Split, the text side", async () => { await page.locator(".source-editor .cm-content").click(); });
await typing("Split, the reading side", async () => { await page.locator(".md-page > .reading").click({ position: { x: 40, y: 10 } }); }, reading);
+106
View File
@@ -0,0 +1,106 @@
// Split view with different tabs: two documents side by side, a browser tab beside a document, a browser tab that covers
// the area and then moves into a pane, the close control of a plugin pane, and the Read beside toggle, in both themes.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("layout/mixedSplits", async ({ page }) => {
const output = await outputDir("layout/mixedSplits");
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({
root: "C:\\mixed-split-workspace",
files: { "a.md": "# Alpha\n\nAlpha text.\n", "b.md": "# Bravo\n\nBravo text.\n" },
});
const snapshot = { profiles: [{ id: "user", name: "User" }], tabs: [], bookmarks: [], settings: { search: "duckduckgo", adblock: true, linkDestination: "internal", personalRules: "", homepage: "", filterLists: [] } };
let next = 0;
return {
...workspace,
browser_connect: () => "window-session",
browser_request: ({ command, args }) => {
if (command === "newTab") { const tabId = "native-" + (++next); snapshot.tabs.push({ id: tabId, profileId: "user", url: "about:blank", title: "Browser", loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; }
if (command === "closeTab") snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId);
return structuredClone(snapshot);
},
};
},
});
const pane = rel => page.locator(`[data-document-path="${rel}"]`);
const browserPane = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator('[data-browser-state="ready"]') });
const tab = name => page.getByRole("tab", { name: new RegExp(name) });
async function openToRight(name) {
await tab(name).click({ button: "right" });
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
}
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
async function newBrowserTab() {
await page.evaluate(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); await pluginHost.get("browser").newTab(); });
await page.locator('[data-browser-state="ready"]').last().waitFor();
}
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="a.md"]').click(); await pane("a.md").locator(".cm-content").waitFor();
// A click in the file tree replaces the current tab, so the second file opens from a new tab.
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
await page.locator('[data-tree-rel="b.md"]').click(); await pane("b.md").locator(".cm-content").waitFor();
assert.equal(await page.getByRole("tab").count(), 2);
await page.waitForFunction(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); return !!pluginHost.get("browser"); });
// Two different documents side by side.
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
assert.equal(await page.locator(".document-pane").count(), 2);
const left = await box(pane("b.md")), right = await box(pane("a.md"));
assert.ok(right.x >= left.x + left.width - 1 && Math.abs(left.y - right.y) < 2, "The documents show side by side");
assert.equal(await pane("a.md").locator(".breadcrumb").innerText(), "a.md", "A pane beside another pane names its file");
await tab("a.md").click({ button: "right" });
assert.equal(await page.getByRole("menuitem", { name: "Open to the right", exact: true }).isDisabled(), true, "A visible tab cannot open again");
await page.keyboard.press("Escape");
// A new browser tab opens in the focused pane. The document that it replaces stays open as a tab.
await newBrowserTab();
assert.equal(await pane("a.md").count(), 0);
assert.equal(await tab("a.md").count(), 1);
const documentBox = await box(pane("b.md")), webBox = await box(browserPane);
assert.ok(webBox.x >= documentBox.x + documentBox.width - 1, "The browser shows beside the document");
assert.ok(Math.abs(webBox.width - documentBox.width) < 4, "The panes share the area");
for (const theme of ["light", "dark"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.screenshot({ path: path.join(output, `document-and-browser-${theme}.png`) });
}
// A click in the document pane makes its tab active. The browser stays visible.
await pane("b.md").locator(".cm-content").click();
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("b.md"));
assert.equal(await browserPane.count(), 1);
// The document opens beside the browser, and the close control of the browser pane leaves the tab open.
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
assert.equal(await page.locator(".document-pane").count(), 3);
await browserPane.getByRole("button", { name: "Close split", exact: true }).click();
assert.equal(await page.locator(".document-pane").count(), 2);
assert.equal(await page.getByRole("tab", { name: /Browser/ }).count(), 1);
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
assert.equal(await page.locator(".document-pane").count(), 1);
// A browser tab that covers the whole area moves into the left pane when a document opens to the right.
await page.getByRole("tab", { name: /Browser/ }).click();
await browserPane.waitFor();
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The browser covers the area");
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
const coverLeft = await box(browserPane), coverRight = await box(pane("a.md"));
assert.ok(coverRight.x >= coverLeft.x + coverLeft.width - 1, "The browser keeps the left pane");
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
await browserPane.waitFor();
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The last pane gives the browser the whole area");
// Read beside is the toggle for the Read view beside the editor.
await tab("b.md").click();
await pane("b.md").locator(".cm-content").waitFor();
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
await pane("b.md").locator(".md-page").waitFor();
console.log(JSON.stringify({ passed: ["two documents side by side", "browser beside a document", "replaced document stays a tab", "focus by click", "plugin pane close control", "covering browser moves into a pane", "last pane releases the browser", "Read beside toggle", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
}, { timeout: 30000 });
+6 -6
View File
@@ -21,7 +21,7 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
const page = await openPage(context), settings = await openPage(context);
const group = page.getByRole("radiogroup", { name: "View", exact: true });
const radio = name => group.getByRole("radio", { name, exact: true });
const split = page.locator(".chrome-bar").getByRole("button", { name: "Split", exact: true });
const split = page.locator(".chrome-bar").getByRole("button", { name: "Read beside", exact: true });
const checked = () => group.getByRole("radio", { checked: true }).getAttribute("aria-label");
const status = () => page.locator(".status").innerText();
async function open(name) {
@@ -86,7 +86,7 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
await page.locator(".live-writer").waitFor();
// Split shows Read beside the current editor. Write and Source keep it. Read ends it.
await chooseView(page, "Split");
await chooseView(page, "Read beside");
assert.equal(await split.getAttribute("aria-pressed"), "true");
await page.locator(".body.split .live-writer").waitFor();
await page.locator(".body.split .md-page").waitFor();
@@ -97,10 +97,10 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
assert.equal(await split.getAttribute("aria-pressed"), "false");
assert.equal(await page.locator(".body.split").count(), 0);
assert.equal(await page.locator(".editor-wrap").isVisible(), false);
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await page.locator(".body.split .source-editor").waitFor();
assert.equal(await checked(), "Source");
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await chooseView(page, "Write");
// The file title shows by default. The General setting hides it in Write and Read.
@@ -123,9 +123,9 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-${theme}.png` });
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-split-${theme}.png` });
await chooseView(page, "Split");
await chooseView(page, "Read beside");
}
// The controls show icons only, at every width (UI-056). The names stay for assistive technology and tooltips.
+3 -3
View File
@@ -72,7 +72,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.keyboard.press("Control+s");
await page.waitForFunction(expected => window.__TEST__.files.get("notes/welcome.md") === expected, original + "Added in source.");
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await page.locator(".md-page h1").first().waitFor();
assert.ok(await page.locator(".source-editor").isVisible());
await page.evaluate(() => {
@@ -153,7 +153,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.locator(".md-page").evaluate(element => { element.scrollTop = 0; });
await page.screenshot({ path: path.join(output, "reader-narrow.png") });
assert.ok(await page.locator(".md-page").evaluate(element => element.scrollWidth <= element.clientWidth + 1));
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await page.waitForFunction(() => {
const host = document.querySelector(".source-editor");
const rendered = host?.querySelector(".cm-editor");
@@ -168,7 +168,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.screenshot({ path: path.join(output, "reader-split-wide.png") });
// A second press ends the Split view.
await chooseView(page, "Split");
await chooseView(page, "Read beside");
await page.locator(".md-page").waitFor({ state: "detached" });
// The editor stores one line break character. The saved file keeps its own line breaks.
assert.equal(await contents(), showcase.replace(/\r\n/g, "\n"));
+2 -2
View File
@@ -118,11 +118,11 @@ await runSmoke("links/sectionLinks", async ({ page }) => {
await readerHeadingAtTop('macOS installer (Apple Silicon)');
await page.locator('.md-page').evaluate(node => { node.scrollTop = 0; });
await readerJump('Linux setup', 'Linux (Intel/AMD 64-bit)');
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await page.locator('.md-page').evaluate(node => { node.scrollTop = 0; });
await readerJump('Windows setup', 'Windows installer');
await page.screenshot({ path:`${output}/split-${theme}-${width}.png` });
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await chooseView(page, 'Source');
await page.locator('.source-editor .cm-content').waitFor();
await chooseView(page, 'Read');
+2 -2
View File
@@ -129,7 +129,7 @@ await runSmoke("tables/formulas", async ({ page }) => {
await page.keyboard.press('Control+e');
assert.equal(await result(3, 1).innerText(), '12');
assert.equal(await result(3, 3).innerText(), '58');
for (const mode of ['Read', 'Split']) {
for (const mode of ['Read', 'Read beside']) {
await chooseView(page, mode);
const preview = page.locator('.md-page table').first();
await preview.waitFor();
@@ -146,7 +146,7 @@ await runSmoke("tables/formulas", async ({ page }) => {
assert.match(await total.innerText(), /=SUM\(D2:D3\)/);
assert.match(await total.innerText(), /=SUM\(B2:B3\)/);
await shot('formulas-off-split');
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await table.waitFor();
assert.equal(await table.locator('.md-table-formula').count(), 0);
assert.match(await cell(3, 3).innerText(), /=SUM\(D2:D3\)/);
+3 -3
View File
@@ -59,7 +59,7 @@ await runSmoke("tabs/menus", async ({ page }) => {
const view = async name => {
await show("d.md");
await item("View").click();
await page.getByRole(name === "Split" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
await page.getByRole(name === "Read beside" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
};
await show("d.md");
await item("View").click();
@@ -68,11 +68,11 @@ await runSmoke("tabs/menus", async ({ page }) => {
await page.keyboard.press("Escape");
await view("Read");
await page.locator(".md-page").waitFor();
await view("Split");
await view("Read beside");
await page.locator(".body.split .md-page").waitFor();
await view("Source");
await page.locator(".body.split .source-editor .cm-content").waitFor();
await view("Split");
await view("Read beside");
await page.locator(".md-page").waitFor({ state: "detached" });
await view("Write");
await page.locator(".live-writer .cm-editor").waitFor();
+2 -2
View File
@@ -65,9 +65,9 @@ await runSmoke("tabs/scroll", async ({ page }) => {
await roundTrip('.cm-scroller', 'Writing');
await chooseView(page, 'Read');
await roundTrip('.md-page', 'Reading');
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await roundTrip('.md-page', 'Split preview');
await chooseView(page, 'Split');
await chooseView(page, 'Read beside');
await chooseView(page, 'Source');
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
await chooseView(page, 'Source');
+43 -2
View File
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView } from "../../../src/lib/workspace/documentPanes.ts";
import { paneBounds } from "../../../src/lib/workspace/splitLayout.ts";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin } from "../../../src/lib/workspace/documentPanes.ts";
import { paneBounds, splitSibling, stackLayout } from "../../../src/lib/workspace/splitLayout.ts";
import { registerSelection, selectedEditorText } from "../../../src/lib/editor/selection.ts";
test("opening a link to the right keeps its source and focuses an existing pane for duplicate targets", () => {
@@ -71,3 +71,44 @@ test("selection readers remain available in both panes and disposal cannot clear
assert.equal(selectedEditorText("b"), "");
replacement();
});
test("a pane shows a document or a plugin view, and each tab has at most one pane", () => {
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
const primary = state.active;
state = splitWithContent(state, primary, { pluginKey: "browser" }, "web");
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], [null, "browser"]]);
assert.equal(state.active, "web");
assert.equal(splitWithContent(state, primary, { pluginKey: "browser" }, "again"), selectPane(state, "web"));
// A document change does not remove the plugin pane.
assert.equal(syncDocumentPanes(state, ["a", "b"], null), state);
// A selected document replaces the view of the active pane. The view stays open as a tab.
const replaced = syncDocumentPanes(state, ["a", "b"], "b");
assert.deepEqual(replaced.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], ["b", null]]);
// A plugin view replaces the document of the active pane, and a shown document selects its pane.
state = showInActivePane(selectPane(replaced, primary), { pluginKey: "board" });
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [[null, "board"], ["b", null]]);
assert.equal(showInActivePane(state, { documentId: "b" }).active, "web");
assert.equal(paneOf(state, { pluginKey: "board" })?.id, primary);
});
test("a closed plugin view leaves its pane, and the last pane gives its plugin view back to the whole area", () => {
let state = syncDocumentPanes(initialDocumentPanes(), ["a"], "a");
state = splitWithContent(state, state.active, { pluginKey: "browser" }, "web", "down");
assert.deepEqual(paneBounds(state.layout).web, { left: 0, top: 50, width: 100, height: 50 });
assert.deepEqual(paneBounds(stackLayout({ direction: "right", first: "x", second: "y" })).y, { left: 0, top: 50, width: 100, height: 50 });
const closed = syncDocumentPanes(state, ["a"], null, []);
assert.deepEqual(closed.panes.map(pane => pane.id), ["document-main"]);
const remaining = closeDocumentPane(state, "document-main");
assert.equal(remaining.active, "web");
const released = releaseSolePlugin(remaining);
assert.equal(released.pluginKey, "browser");
assert.deepEqual([released.state.panes[0].documentId, released.state.panes[0].pluginKey], [null, null]);
assert.equal(releaseSolePlugin(closed).state, closed);
});
test("the split sibling names the pane that a plugin view opened beside", () => {
const tree = { direction: "right" as const, first: "a", second: { direction: "down" as const, first: "b", second: "c" } };
assert.deepEqual(splitSibling(tree, "c"), { direction: "down", sibling: "b" });
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
assert.equal(splitSibling("a", "a"), null);
});