Resize panes and drag tabs into panes
- A divider between two panes changes their sizes, with the pointer or the keyboard. A double-click gives equal sizes. - A tab that the user drags from the tab bar to a pane replaces its content, or opens a new pane on its right or bottom side. - The file tree menu has "Open to the right", also for PDF files and boards. - "New tab to the right" and "New tab below" of a browser tab open a new tab with the home page beside it. They replace "Split right" and "Split down". - New smoke test: a PDF file beside a note.
This commit is contained in:
@@ -1163,12 +1163,12 @@ Update 2026-10-29: The native Terminal feature keeps the 65% cap on `--rs-select
|
|||||||
- Status: Implemented for user review
|
- 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.
|
- 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.
|
- 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**.
|
- 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**. The file tree menu also has **Open to the right**, also for PDF files and boards. A divider between two panes changes their sizes, with the pointer or the keyboard. A double-click gives the panes equal sizes. A tab that the user drags from the tab bar to a pane replaces the content of that pane. A drop on the right or bottom part of a pane opens a new pane there. A hint shows the place of the drop.
|
||||||
- Reason: "Split" named two different things. Users compare a note with a different note or with a web page.
|
- Reason: "Split" named two different things. Users compare a note with a different note, with a web page, or with a PDF file. Equal pane sizes did not fit a web page or a PDF page beside a note.
|
||||||
- Scope: Document panes, plugin editor tabs, the tab menu, and the view control.
|
- Scope: Document panes, plugin editor tabs, the tab menu, the tab bar, the file tree 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.
|
- Shared implementation: `src/lib/workspace/documentPanes.ts`, `src/lib/workspace/splitLayout.ts` (`stackLayout`, `splitSibling`, `splitDividers`, `setSplitRatio`), `src/lib/layout/DocumentArea.svelte`, `src/lib/layout/TabBar.svelte` (`onDragAt`, `onDropAt`), 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.
|
- Exceptions: In the menu of a browser tab, **New tab to the right** and **New tab below** open a new browser tab with the home page in a pane beside the tab. These items replace **Split right** and **Split down**, which opened a copy of the page in a split of plugin views only. The separate browser window keeps its own plugin split.
|
||||||
- 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.
|
- Narrow layout: An area of 640 pixels or less shows the panes one above the other, in the same order and with the same ratios. The area does not scroll. Each pane keeps its own scroll bar. A tab drop opens a new pane only below.
|
||||||
- Evidence: `tests/smoke/layout/mixedSplits.smoke.mjs`, `tests/smoke/layout/splits.smoke.mjs`, and `tests/unit/layout/documentPanes.spec.ts`.
|
- Evidence: `tests/smoke/layout/mixedSplits.smoke.mjs`, `tests/smoke/layout/pdfBesideNote.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).
|
- 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.
|
- Limits: A tab from a different window opens in the tab bar, not in a pane. Browser checks use desktop service mocks. Native desktop acceptance remains open.
|
||||||
|
|||||||
+10
-4
@@ -186,15 +186,21 @@ This includes PDF tabs and plugin tabs that show a file. RuneStone reads the con
|
|||||||
|
|
||||||
### Show tabs side by side
|
### Show tabs side by side
|
||||||
|
|
||||||
1. Right-click a tab that is not visible.
|
Use panes to see two tabs at the same time. For example, browse the web or read a PDF file in one pane, and write a note in the other pane.
|
||||||
|
|
||||||
|
1. Right-click a tab that is not visible, or a file in the file tree.
|
||||||
2. Select **Open to the right**.
|
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.
|
The tab opens in a new pane to the right of the active pane. A pane shows a document, a PDF file, or a plugin tab, for example a browser tab. A tab shows in one pane at a time.
|
||||||
|
|
||||||
|
You can also drag a tab from the tab bar to a pane. A drop on the middle of the pane shows the tab in that pane. A drop on the right or bottom part opens a new pane there. A hint shows the place before you release the tab.
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
|
- Drag the divider between two panes to change their sizes. Double-click the divider to give the panes equal sizes. With the keyboard, focus the divider and use the arrow keys.
|
||||||
- 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 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.
|
- A browser tab or a PDF tab that fills the area moves to the left pane when a tab opens to the right. When one pane is left, its 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.
|
- In the menu of a browser tab, **New tab to the right** and **New tab below** open a new browser tab with the home page in a pane beside it.
|
||||||
|
- The link menu also has **Open to the right**. In a narrow window, the panes show one above the other.
|
||||||
|
|
||||||
## Save your work
|
## Save your work
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ export async function activate(api: PluginApi) {
|
|||||||
const id = `tab-${crypto.randomUUID()}`;
|
const id = `tab-${crypto.randomUUID()}`;
|
||||||
const saved: SavedView = { view: id, profileId, url, runtimeId: '' };
|
const saved: SavedView = { view: id, profileId, url, runtimeId: '' };
|
||||||
const run = (command: string, args?: Record<string, unknown>) => { void saved.control?.action(command, args); };
|
const run = (command: string, args?: Record<string, unknown>) => { void saved.control?.action(command, args); };
|
||||||
|
// A new tab with the home page of the profile opens in a pane beside this tab.
|
||||||
const split = (direction: 'right' | 'down') => {
|
const split = (direction: 'right' | 'down') => {
|
||||||
const current = get(state)?.tabs.find(tab => tab.id === saved.runtimeId);
|
const current = get(state)?.tabs.find(tab => tab.id === saved.runtimeId);
|
||||||
void open(current?.profileId || saved.profileId, current?.url || saved.url || 'about:blank', { split: direction, relativeTo: id });
|
void open(current?.profileId || saved.profileId, undefined, { split: direction, relativeTo: id });
|
||||||
};
|
};
|
||||||
api.registerView({ id, title: 'Browser', placement: 'editor', icon: 'globe', pinned, launcher: false,
|
api.registerView({ id, title: 'Browser', placement: 'editor', icon: 'globe', pinned, launcher: false,
|
||||||
tabDragData: ({ pinned }) => {
|
tabDragData: ({ pinned }) => {
|
||||||
@@ -65,8 +66,8 @@ export async function activate(api: PluginApi) {
|
|||||||
return [
|
return [
|
||||||
{ separator: true },
|
{ separator: true },
|
||||||
{ label: tr("Move to new window"), icon: 'external', disabled: !ready, run: () => run('moveToWindow', { pinned }) },
|
{ label: tr("Move to new window"), icon: 'external', disabled: !ready, run: () => run('moveToWindow', { pinned }) },
|
||||||
{ label: tr("Split right"), icon: 'split-right', disabled: !ready, run: () => split('right') },
|
{ label: tr("New tab to the right"), icon: 'split-right', disabled: !ready, run: () => split('right') },
|
||||||
{ label: tr("Split down"), icon: 'split-down', disabled: !ready, run: () => split('down') },
|
{ label: tr("New tab below"), icon: 'split-down', disabled: !ready, run: () => split('down') },
|
||||||
{ separator: true },
|
{ separator: true },
|
||||||
{ label: tr("Find…"), icon: 'search', shortcut: keys('Mod+F'), disabled: !ready, run: () => { api.openView(id); void saved.control?.find(); } },
|
{ label: tr("Find…"), icon: 'search', shortcut: keys('Mod+F'), disabled: !ready, run: () => { api.openView(id); void saved.control?.find(); } },
|
||||||
{ label: tr("Open in default browser"), icon: 'external', disabled: !web, run: () => run('openExternal') },
|
{ label: tr("Open in default browser"), icon: 'external', disabled: !web, run: () => run('openExternal') },
|
||||||
|
|||||||
@@ -3300,8 +3300,12 @@ export const messageRows: [string, string, string, string][] = [
|
|||||||
["The workspace changed. File moves stopped.", "L’espace de travail a changé. Les déplacements de fichiers sont arrêtés.", "ワークスペースが変更されました。ファイルの移動を停止しました。", "工作区已更改。文件移动已停止。"],
|
["The workspace changed. File moves stopped.", "L’espace de travail a changé. Les déplacements de fichiers sont arrêtés.", "ワークスペースが変更されました。ファイルの移動を停止しました。", "工作区已更改。文件移动已停止。"],
|
||||||
["The workspace changed. Paste stopped.", "L’espace de travail a changé. Le collage est arrêté.", "ワークスペースが変更されました。貼り付けを停止しました。", "工作区已更改。粘贴已停止。"],
|
["The workspace changed. Paste stopped.", "L’espace de travail a changé. Le collage est arrêté.", "ワークスペースが変更されました。貼り付けを停止しました。", "工作区已更改。粘贴已停止。"],
|
||||||
["Move to new window", "Déplacer vers une nouvelle fenêtre", "新しいウィンドウに移動", "移到新窗口"],
|
["Move to new window", "Déplacer vers une nouvelle fenêtre", "新しいウィンドウに移動", "移到新窗口"],
|
||||||
["Split right", "Scinder à droite", "右に分割", "向右拆分"],
|
["New tab to the right", "Nouvel onglet à droite", "右に新しいタブ", "在右侧新建标签页"],
|
||||||
["Split down", "Scinder vers le bas", "下に分割", "向下拆分"],
|
["New tab below", "Nouvel onglet en dessous", "下に新しいタブ", "在下方新建标签页"],
|
||||||
|
["Resize panes", "Redimensionner les volets", "ペインのサイズを変更", "调整窗格大小"],
|
||||||
|
["Drag to resize the panes. Double-click to give them equal sizes.", "Faites glisser pour redimensionner les volets. Double-cliquez pour leur donner la même taille.", "ドラッグしてペインのサイズを変更します。ダブルクリックすると同じサイズになります。", "拖动以调整窗格大小。双击使窗格大小相同。"],
|
||||||
|
["Show here", "Afficher ici", "ここに表示", "在此显示"],
|
||||||
|
["Open below", "Ouvrir en dessous", "下に開く", "在下方打开"],
|
||||||
["Find…", "Rechercher…", "検索…", "查找…"],
|
["Find…", "Rechercher…", "検索…", "查找…"],
|
||||||
["Open in default browser", "Ouvrir dans le navigateur par défaut", "既定のブラウザーで開く", "在默认浏览器中打开"],
|
["Open in default browser", "Ouvrir dans le navigateur par défaut", "既定のブラウザーで開く", "在默认浏览器中打开"],
|
||||||
["Invalid browser tab transfer.", "Transfert d’onglet de navigateur non valide.", "ブラウザータブの移動が無効です。", "浏览器标签页转移无效。"],
|
["Invalid browser tab transfer.", "Transfert d’onglet de navigateur non valide.", "ブラウザータブの移動が無効です。", "浏览器标签页转移无效。"],
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// The document area: the panes of documents and plugin editor views, 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.
|
// 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.
|
// Without a pane, the layer shows the focused plugin view over the whole area. In a pane, the view covers its pane.
|
||||||
|
// A divider between two panes changes the ratio of their split. A tab that the user drags over the area shows a drop hint.
|
||||||
import type { ComponentProps } from "svelte";
|
import type { ComponentProps } from "svelte";
|
||||||
import { t } from "$lib/i18n";
|
import { t } from "$lib/i18n";
|
||||||
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
||||||
@@ -11,19 +12,21 @@
|
|||||||
import EditorPane from "./EditorPane.svelte";
|
import EditorPane from "./EditorPane.svelte";
|
||||||
import Icon from "$lib/ui/Icon.svelte";
|
import Icon from "$lib/ui/Icon.svelte";
|
||||||
import IconButton from "$lib/ui/IconButton.svelte";
|
import IconButton from "$lib/ui/IconButton.svelte";
|
||||||
import { paneBounds, stackLayout, type SplitLayout } from "$lib/workspace/splitLayout";
|
import { paneBounds, splitDividers, stackLayout, type SplitDivider, type SplitLayout, type SplitPath } from "$lib/workspace/splitLayout";
|
||||||
|
import type { PaneDrop } from "$lib/workspace/documentPanes";
|
||||||
|
import { attachTooltip } from "$lib/ui/tooltip";
|
||||||
import type { ViewMode } from "./ViewModes.svelte";
|
import type { ViewMode } from "./ViewModes.svelte";
|
||||||
import TabBar from "./TabBar.svelte";
|
|
||||||
|
|
||||||
type EditorProps = ComponentProps<typeof EditorPane>;
|
type EditorProps = ComponentProps<typeof EditorPane>;
|
||||||
type DocumentView = { id: string; reading: boolean; split: boolean; buffer: OpenBuffer | null; pluginKey: string | null };
|
type DocumentView = { id: string; reading: boolean; split: boolean; buffer: OpenBuffer | null; pluginKey: string | null };
|
||||||
type Bounds = { left: number; top: number; width: number; height: number };
|
/** The pane under a dragged tab, and the place of the drop on it. */
|
||||||
|
type DropTarget = { pane: string; zone: PaneDrop };
|
||||||
type Props = {
|
type Props = {
|
||||||
/** The focused plugin view covers the whole area. */
|
/** The focused plugin view covers the whole area. */
|
||||||
pluginCover: boolean;
|
pluginCover: boolean;
|
||||||
split: boolean;
|
/** The drop hint of a dragged tab. */
|
||||||
pluginBounds: Record<string, Bounds | undefined>;
|
drop: DropTarget | null;
|
||||||
tabBar: ComponentProps<typeof TabBar>;
|
onResize: (path: SplitPath, ratio: number) => void;
|
||||||
pluginPaneComponents: Record<string, PluginEditor | undefined>;
|
pluginPaneComponents: Record<string, PluginEditor | undefined>;
|
||||||
documentViews: DocumentView[];
|
documentViews: DocumentView[];
|
||||||
layout: SplitLayout;
|
layout: SplitLayout;
|
||||||
@@ -52,7 +55,7 @@
|
|||||||
onCursor: (pane: DocumentView, line: number, column: number) => void;
|
onCursor: (pane: DocumentView, line: number, column: number) => void;
|
||||||
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
|
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
|
||||||
};
|
};
|
||||||
let { pluginCover, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, layout, activePane, paneComponents = $bindable(),
|
let { pluginCover, drop, onResize, pluginPaneComponents = $bindable(), documentViews, layout, activePane, paneComponents = $bindable(),
|
||||||
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
|
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
|
||||||
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onCursor, onOpenLink }: Props = $props();
|
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onCursor, onOpenLink }: Props = $props();
|
||||||
|
|
||||||
@@ -66,9 +69,85 @@
|
|||||||
if (host) onFocusPane(host);
|
if (host) onFocusPane(host);
|
||||||
else if ($pluginView?.key !== view.key) selectPluginEditor(view);
|
else if ($pluginView?.key !== view.key) selectPluginEditor(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let area: HTMLElement;
|
||||||
|
const full = { left: 0, top: 0, width: 100, height: 100 };
|
||||||
|
const dividers = $derived(pluginCover || !several ? [] : splitDividers(stacked ? stackLayout(layout) : layout));
|
||||||
|
/** The place of the divider: the line between the two sides of its split, in percent of the area. */
|
||||||
|
function dividerStyle(divider: SplitDivider) {
|
||||||
|
const { bounds: box, ratio } = divider;
|
||||||
|
return divider.direction === "right"
|
||||||
|
? `left:${box.left + box.width * ratio}%;top:${box.top}%;height:${box.height}%`
|
||||||
|
: `top:${box.top + box.height * ratio}%;left:${box.left}%;width:${box.width}%`;
|
||||||
|
}
|
||||||
|
function ratioAt(divider: SplitDivider, x: number, y: number) {
|
||||||
|
const rect = area.getBoundingClientRect(), box = divider.bounds;
|
||||||
|
return divider.direction === "right"
|
||||||
|
? (x - rect.left - rect.width * box.left / 100) / (rect.width * box.width / 100)
|
||||||
|
: (y - rect.top - rect.height * box.top / 100) / (rect.height * box.height / 100);
|
||||||
|
}
|
||||||
|
let resizing = $state<"right" | "down" | null>(null);
|
||||||
|
function startResize(event: PointerEvent, divider: SplitDivider) {
|
||||||
|
if (event.button !== 0) return;
|
||||||
|
event.preventDefault();
|
||||||
|
const handle = event.currentTarget as HTMLElement;
|
||||||
|
handle.setPointerCapture(event.pointerId);
|
||||||
|
handle.focus({ preventScroll: true });
|
||||||
|
resizing = divider.direction;
|
||||||
|
const move = (next: PointerEvent) => onResize(divider.path, ratioAt(divider, next.clientX, next.clientY));
|
||||||
|
const end = () => {
|
||||||
|
resizing = null;
|
||||||
|
handle.removeEventListener("pointermove", move);
|
||||||
|
handle.removeEventListener("pointerup", end);
|
||||||
|
handle.removeEventListener("pointercancel", end);
|
||||||
|
};
|
||||||
|
handle.addEventListener("pointermove", move);
|
||||||
|
handle.addEventListener("pointerup", end);
|
||||||
|
handle.addEventListener("pointercancel", end);
|
||||||
|
}
|
||||||
|
function resizeKey(event: KeyboardEvent, divider: SplitDivider) {
|
||||||
|
const steps: Record<string, number> = divider.direction === "right" ? { ArrowLeft: -0.05, ArrowRight: 0.05 } : { ArrowUp: -0.05, ArrowDown: 0.05 };
|
||||||
|
if (event.key in steps) onResize(divider.path, divider.ratio + steps[event.key]);
|
||||||
|
else if (event.key === "Home") onResize(divider.path, 0.1);
|
||||||
|
else if (event.key === "End") onResize(divider.path, 0.9);
|
||||||
|
else if (event.key === "Enter") onResize(divider.path, 0.5);
|
||||||
|
else return;
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
function tooltip(node: HTMLElement, text: string) {
|
||||||
|
let label = text;
|
||||||
|
const dispose = attachTooltip(node, () => label);
|
||||||
|
return { update(value: string) { label = value; }, destroy: dispose };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The drop target under a point: a pane, and the place on it. The right and bottom sides open a new pane.
|
||||||
|
* While a plugin view covers the area, the area is one pane. A narrow area opens new panes only below.
|
||||||
|
*/
|
||||||
|
export function dropAt(x: number, y: number): DropTarget | null {
|
||||||
|
const rect = area?.getBoundingClientRect();
|
||||||
|
if (!rect || !rect.width || !rect.height || x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) return null;
|
||||||
|
const px = (x - rect.left) / rect.width * 100, py = (y - rect.top) / rect.height * 100;
|
||||||
|
const pane = pluginCover ? activePane : documentViews.find(view => {
|
||||||
|
const box = bounds[view.id];
|
||||||
|
return box && px >= box.left && px <= box.left + box.width && py >= box.top && py <= box.top + box.height;
|
||||||
|
})?.id;
|
||||||
|
const box = pane ? (pluginCover ? full : bounds[pane]) : undefined;
|
||||||
|
if (!pane || !box) return null;
|
||||||
|
const rx = (px - box.left) / box.width, ry = (py - box.top) / box.height;
|
||||||
|
return { pane, zone: rx > 0.7 && !stacked ? "right" : ry > 0.7 ? "down" : "center" };
|
||||||
|
}
|
||||||
|
const dropBox = $derived.by(() => {
|
||||||
|
if (!drop) return null;
|
||||||
|
const box = pluginCover ? full : bounds[drop.pane];
|
||||||
|
if (!box) return null;
|
||||||
|
if (drop.zone === "right") return { ...box, left: box.left + box.width / 2, width: box.width / 2 };
|
||||||
|
if (drop.zone === "down") return { ...box, top: box.top + box.height / 2, height: box.height / 2 };
|
||||||
|
return box;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main class="center" bind:clientWidth={width}>
|
<main class="center" class:resizing={!!resizing} class:resizing-down={resizing === "down"} bind:this={area} bind:clientWidth={width}>
|
||||||
<div class="editor-host" class:plugin-covered={pluginCover}>
|
<div class="editor-host" class:plugin-covered={pluginCover}>
|
||||||
<div class="document-panes" class:split={several}>
|
<div class="document-panes" class:split={several}>
|
||||||
{#each documentViews as pane (pane.id)}
|
{#each documentViews as pane (pane.id)}
|
||||||
@@ -130,9 +209,9 @@
|
|||||||
<div class="plugin-panes">
|
<div class="plugin-panes">
|
||||||
{#each $pluginEditors as view (view.key)}
|
{#each $pluginEditors as view (view.key)}
|
||||||
{@const host = pluginCover ? undefined : hosts.get(view.key)}
|
{@const host = pluginCover ? undefined : hosts.get(view.key)}
|
||||||
{@const box = pluginCover ? pluginBounds[view.key] : host ? bounds[host] : undefined}
|
{@const box = pluginCover ? ($pluginView?.key === view.key ? full : undefined) : host ? bounds[host] : undefined}
|
||||||
<!-- svelte-ignore a11y_no_static_element_interactions (Focus selects the pane that owns the input.) -->
|
<!-- 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}
|
<div class="plugin-pane" class:inactive={!box} class:embedded={!!host}
|
||||||
class:focused={host ? activePane === host : $pluginView?.key === view.key}
|
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}
|
class:edge-left={!!host && (box?.left ?? 0) > 0} class:edge-top={!!host && (box?.top ?? 0) > 0}
|
||||||
data-plugin-pane={view.key}
|
data-plugin-pane={view.key}
|
||||||
@@ -140,9 +219,7 @@
|
|||||||
style:width={`${box?.width ?? 100}%`} style:height={`${box?.height ?? 100}%`}
|
style:width={`${box?.width ?? 100}%`} style:height={`${box?.height ?? 100}%`}
|
||||||
onfocusin={() => focusPlugin(view, host)}
|
onfocusin={() => focusPlugin(view, host)}
|
||||||
onpointerdowncapture={() => focusPlugin(view, host)}>
|
onpointerdowncapture={() => focusPlugin(view, host)}>
|
||||||
{#if pluginCover && split && box}
|
{#if host && several}
|
||||||
<TabBar {...tabBar} tabs={tabBar.tabs.filter(tab => tab.id === view.key)} />
|
|
||||||
{:else if host && several}
|
|
||||||
<div class="pane-bar">
|
<div class="pane-bar">
|
||||||
<span class="pane-title" title={view.title}>{view.title}</span>
|
<span class="pane-title" title={view.title}>{view.title}</span>
|
||||||
<IconButton icon="close" label={$t("Close split")} onclick={() => onCloseSplit(host)} />
|
<IconButton icon="close" label={$t("Close split")} onclick={() => onCloseSplit(host)} />
|
||||||
@@ -152,6 +229,22 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
{#each dividers as divider (divider.path.join("/"))}
|
||||||
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (A focusable separator is the splitter pattern.) -->
|
||||||
|
<div class="divider" class:vertical={divider.direction === "right"} style={dividerStyle(divider)}
|
||||||
|
role="separator" tabindex="0" aria-label={$t("Resize panes")}
|
||||||
|
aria-orientation={divider.direction === "right" ? "vertical" : "horizontal"}
|
||||||
|
aria-valuemin={10} aria-valuemax={90} aria-valuenow={Math.round(divider.ratio * 100)}
|
||||||
|
use:tooltip={$t("Drag to resize the panes. Double-click to give them equal sizes.")}
|
||||||
|
onpointerdown={event => startResize(event, divider)}
|
||||||
|
ondblclick={() => onResize(divider.path, 0.5)}
|
||||||
|
onkeydown={event => resizeKey(event, divider)}></div>
|
||||||
|
{/each}
|
||||||
|
{#if dropBox && drop}
|
||||||
|
<div class="drop-hint" data-drop-zone={drop.zone} style:left={`${dropBox.left}%`} style:top={`${dropBox.top}%`} style:width={`${dropBox.width}%`} style:height={`${dropBox.height}%`}>
|
||||||
|
<span>{drop.zone === "center" ? $t("Show here") : drop.zone === "right" ? $t("Open to the right") : $t("Open below")}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -197,11 +290,23 @@
|
|||||||
.plugin-panes { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
|
.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 { 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.embedded { background: var(--rs-bg); }
|
||||||
.plugin-pane.split { border: 1px solid var(--rs-border); }
|
|
||||||
.plugin-pane.split.focused { border-color: var(--rs-accent); }
|
|
||||||
.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. */
|
/* 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); }
|
.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); }
|
.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; }
|
.pane-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
/* A divider is a wide, invisible target over the border between two panes. It shows the accent color on hover and focus. */
|
||||||
|
.divider { position: absolute; z-index: 3; height: 8px; margin-top: -4px; cursor: row-resize; touch-action: none; }
|
||||||
|
.divider.vertical { width: 8px; margin-top: 0; margin-left: -4px; cursor: col-resize; }
|
||||||
|
.divider::after { content: ""; position: absolute; inset: 3px 0; border-radius: 1px; }
|
||||||
|
.divider.vertical::after { inset: 0 3px; }
|
||||||
|
.divider:hover::after, .divider:focus-visible::after, .center.resizing .divider:focus::after { background: var(--rs-accent); }
|
||||||
|
.divider:focus-visible { outline: none; }
|
||||||
|
.center.resizing { cursor: col-resize; user-select: none; }
|
||||||
|
.center.resizing-down { cursor: row-resize; }
|
||||||
|
.center.resizing .document-panes, .center.resizing .plugin-pane { pointer-events: none; }
|
||||||
|
/* The drop hint shows where a dragged tab goes. */
|
||||||
|
.drop-hint { position: absolute; z-index: 4; box-sizing: border-box; display: flex; align-items: center; justify-content: center; pointer-events: none;
|
||||||
|
border: 2px solid var(--rs-accent); border-radius: var(--rs-control-radius); background: color-mix(in srgb, var(--rs-accent) 16%, transparent); }
|
||||||
|
.drop-hint span { padding: 4px 10px; border-radius: var(--rs-control-radius); background: var(--rs-accent); color: var(--rs-on-accent); font-weight: 600; }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -43,6 +43,8 @@
|
|||||||
workspaceRoot: string;
|
workspaceRoot: string;
|
||||||
activePath: string | null;
|
activePath: string | null;
|
||||||
onOpenFile: (entry: TreeEntry, newTab?: boolean) => void;
|
onOpenFile: (entry: TreeEntry, newTab?: boolean) => void;
|
||||||
|
/** Open the file in a new pane to the right of the active pane. */
|
||||||
|
onOpenRight?: (entry: TreeEntry) => void;
|
||||||
session: WorkspaceSession;
|
session: WorkspaceSession;
|
||||||
onStatus?: (message: string) => void;
|
onStatus?: (message: string) => void;
|
||||||
onCreated?: (entry: TreeEntry) => void;
|
onCreated?: (entry: TreeEntry) => void;
|
||||||
@@ -56,6 +58,7 @@
|
|||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
activePath,
|
activePath,
|
||||||
onOpenFile,
|
onOpenFile,
|
||||||
|
onOpenRight,
|
||||||
session,
|
session,
|
||||||
onStatus,
|
onStatus,
|
||||||
onCreated,
|
onCreated,
|
||||||
@@ -878,6 +881,7 @@
|
|||||||
...(!multiple && entry.kind === "folder" ? [...paneMenuItems(entry.rel_path), { kind: "sep" as const }] : []),
|
...(!multiple && entry.kind === "folder" ? [...paneMenuItems(entry.rel_path), { kind: "sep" as const }] : []),
|
||||||
...(!multiple && entry.kind === "file" ? [
|
...(!multiple && entry.kind === "file" ? [
|
||||||
{ kind: "action" as const, label: $t("Open in new tab"), icon: "tab" as const, run: () => onOpenFile(entry, true) },
|
{ kind: "action" as const, label: $t("Open in new tab"), icon: "tab" as const, run: () => onOpenFile(entry, true) },
|
||||||
|
...(onOpenRight ? [{ kind: "action" as const, label: $t("Open to the right"), icon: "split-right" as const, run: () => onOpenRight(entry) }] : []),
|
||||||
{ kind: "action" as const, label: $t("Open in default app"), icon: "external" as const, run: () => { void workspaceOpenDefault(entry.rel_path).catch(reason => error = String(reason)); } },
|
{ kind: "action" as const, label: $t("Open in default app"), icon: "external" as const, run: () => { void workspaceOpenDefault(entry.rel_path).catch(reason => error = String(reason)); } },
|
||||||
] : []),
|
] : []),
|
||||||
terminalItem(parent),
|
terminalItem(parent),
|
||||||
|
|||||||
@@ -29,13 +29,14 @@
|
|||||||
onHelp: () => void;
|
onHelp: () => void;
|
||||||
onSettings: () => void;
|
onSettings: () => void;
|
||||||
onOpenFile: (entry: TreeEntry, line?: number, target?: "current" | "new") => void;
|
onOpenFile: (entry: TreeEntry, line?: number, target?: "current" | "new") => void;
|
||||||
|
onOpenRight?: (entry: TreeEntry) => void;
|
||||||
onCreated: (entry: TreeEntry) => void;
|
onCreated: (entry: TreeEntry) => void;
|
||||||
onSaveTemplate: (entry: TreeEntry) => void;
|
onSaveTemplate: (entry: TreeEntry) => void;
|
||||||
onManageTemplates: () => void;
|
onManageTemplates: () => void;
|
||||||
onStatus: (message: string) => void;
|
onStatus: (message: string) => void;
|
||||||
};
|
};
|
||||||
let { workspace, session, leftView, keysActive, showInternal, activePath, searchRequest, fileTree = $bindable(), workspaceAnchor = $bindable(),
|
let { workspace, session, leftView, keysActive, showInternal, activePath, searchRequest, fileTree = $bindable(), workspaceAnchor = $bindable(),
|
||||||
onOpenFile, onCreated, onSaveTemplate, onManageTemplates, onStatus, onChooseWorkspace, onHelp, onSettings }: Props = $props();
|
onOpenFile, onOpenRight, onCreated, onSaveTemplate, onManageTemplates, onStatus, onChooseWorkspace, onHelp, onSettings }: Props = $props();
|
||||||
|
|
||||||
function tooltip(node: HTMLElement, text: string) {
|
function tooltip(node: HTMLElement, text: string) {
|
||||||
let current = text;
|
let current = text;
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
{onManageTemplates}
|
{onManageTemplates}
|
||||||
{activePath}
|
{activePath}
|
||||||
onOpenFile={(entry, newTab) => onOpenFile(entry, undefined, newTab ? "new" : "current")}
|
onOpenFile={(entry, newTab) => onOpenFile(entry, undefined, newTab ? "new" : "current")}
|
||||||
|
{onOpenRight}
|
||||||
{session}
|
{session}
|
||||||
{keysActive}
|
{keysActive}
|
||||||
{onCreated}
|
{onCreated}
|
||||||
|
|||||||
@@ -27,9 +27,14 @@
|
|||||||
tabDragData?: (tab: WorkbenchTab) => string | undefined;
|
tabDragData?: (tab: WorkbenchTab) => string | undefined;
|
||||||
onDropTab?: (data: string, index: number) => void;
|
onDropTab?: (data: string, index: number) => void;
|
||||||
onDetach?: (tab: WorkbenchTab) => void;
|
onDetach?: (tab: WorkbenchTab) => void;
|
||||||
|
/** A tab drag outside the tab bar. The result tells whether the point can take the tab, for example a document pane. */
|
||||||
|
onDragAt?: (relPath: string, x: number, y: number) => boolean;
|
||||||
|
/** A tab drop outside the tab bar. The result tells whether the drop used the tab. */
|
||||||
|
onDropAt?: (relPath: string, x: number, y: number) => boolean;
|
||||||
|
onDragEnd?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { tabs, activePath, onSelect, onClose, onMove, onCloseTabs, onPin, fileActions, tabActions = () => [], tabDragData = () => undefined, onDropTab, onDetach }: Props = $props();
|
let { tabs, activePath, onSelect, onClose, onMove, onCloseTabs, onPin, fileActions, tabActions = () => [], tabDragData = () => undefined, onDropTab, onDetach, onDragAt, onDropAt, onDragEnd }: Props = $props();
|
||||||
const transferType = "application/x-runestone-tab";
|
const transferType = "application/x-runestone-tab";
|
||||||
let bar: HTMLDivElement;
|
let bar: HTMLDivElement;
|
||||||
let dragged = $state<string | null>(null);
|
let dragged = $state<string | null>(null);
|
||||||
@@ -61,6 +66,34 @@
|
|||||||
suppressClick = true;
|
suppressClick = true;
|
||||||
event.dataTransfer.effectAllowed = "move";
|
event.dataTransfer.effectAllowed = "move";
|
||||||
event.dataTransfer.setData(transferType, data);
|
event.dataTransfer.setData(transferType, data);
|
||||||
|
watchAreaDrop(tab.relPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A tab that leaves the tab bar can go to a pane of the document area. The listeners run first, in the capture
|
||||||
|
// phase, so that an editor under the pointer does not take the drop.
|
||||||
|
let stopAreaDrop = () => {};
|
||||||
|
function watchAreaDrop(path: string) {
|
||||||
|
stopAreaDrop();
|
||||||
|
if (!onDragAt || !onDropAt) return;
|
||||||
|
const inBar = (event: DragEvent) => event.target instanceof Node && bar.contains(event.target);
|
||||||
|
const over = (event: DragEvent) => {
|
||||||
|
if (inBar(event) || !onDragAt?.(path, event.clientX, event.clientY)) return;
|
||||||
|
event.preventDefault(); event.stopPropagation();
|
||||||
|
if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
|
||||||
|
};
|
||||||
|
const drop = (event: DragEvent) => {
|
||||||
|
if (inBar(event) || !onDropAt?.(path, event.clientX, event.clientY)) return;
|
||||||
|
event.preventDefault(); event.stopPropagation();
|
||||||
|
finishTabTransfer();
|
||||||
|
};
|
||||||
|
window.addEventListener("dragover", over, true);
|
||||||
|
window.addEventListener("drop", drop, true);
|
||||||
|
stopAreaDrop = () => {
|
||||||
|
window.removeEventListener("dragover", over, true);
|
||||||
|
window.removeEventListener("drop", drop, true);
|
||||||
|
stopAreaDrop = () => {};
|
||||||
|
onDragEnd?.();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferIndex(x: number) {
|
function transferIndex(x: number) {
|
||||||
@@ -85,6 +118,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function finishTabTransfer() {
|
function finishTabTransfer() {
|
||||||
|
stopAreaDrop();
|
||||||
dragged = dropBefore = dropAfter = null; receiving = false; suppressClick = false;
|
dragged = dropBefore = dropAfter = null; receiving = false; suppressClick = false;
|
||||||
cancelAnimationFrame(transferFrame); transferFrame = 0;
|
cancelAnimationFrame(transferFrame); transferFrame = 0;
|
||||||
}
|
}
|
||||||
@@ -289,6 +323,7 @@
|
|||||||
frame = requestAnimationFrame(scroll);
|
frame = requestAnimationFrame(scroll);
|
||||||
};
|
};
|
||||||
const clean = () => {
|
const clean = () => {
|
||||||
|
if (started) onDragEnd?.();
|
||||||
if (pointerTarget.hasPointerCapture(pointerId)) pointerTarget.releasePointerCapture(pointerId);
|
if (pointerTarget.hasPointerCapture(pointerId)) pointerTarget.releasePointerCapture(pointerId);
|
||||||
cancelAnimationFrame(frame);
|
cancelAnimationFrame(frame);
|
||||||
dragged = dropBefore = dropAfter = null;
|
dragged = dropBefore = dropAfter = null;
|
||||||
@@ -306,15 +341,19 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!started) { started = true; suppressClick = true; dragged = path; frame = requestAnimationFrame(scroll); }
|
if (!started) { started = true; suppressClick = true; dragged = path; frame = requestAnimationFrame(scroll); }
|
||||||
update();
|
update();
|
||||||
|
if (destination === null) onDragAt?.(path, x, y);
|
||||||
|
else onDragEnd?.();
|
||||||
};
|
};
|
||||||
const onUp = (e: PointerEvent) => {
|
const onUp = (e: PointerEvent) => {
|
||||||
if (e.pointerId !== pointerId) return;
|
if (e.pointerId !== pointerId) return;
|
||||||
x = e.clientX; y = e.clientY;
|
x = e.clientX; y = e.clientY;
|
||||||
if (started) update();
|
if (started) update();
|
||||||
const target = destination;
|
const target = destination;
|
||||||
|
const wasStarted = started;
|
||||||
clean();
|
clean();
|
||||||
if (started && target !== null) void move(path, target);
|
if (wasStarted && target !== null) void move(path, target);
|
||||||
else if (started && (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight)) {
|
else if (wasStarted && onDropAt?.(path, x, y)) return;
|
||||||
|
else if (wasStarted && (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight)) {
|
||||||
const tab = tabs.find(tab => tab.relPath === path);
|
const tab = tabs.find(tab => tab.relPath === path);
|
||||||
if (tab) onDetach?.(tab);
|
if (tab) onDetach?.(tab);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
import { WorkspaceSession } from "$lib/workspace/session.svelte";
|
import { WorkspaceSession } from "$lib/workspace/session.svelte";
|
||||||
import { retainEditorStates } from "$lib/editor/editorStates";
|
import { retainEditorStates } from "$lib/editor/editorStates";
|
||||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView,
|
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView,
|
||||||
paneOf, showInActivePane, splitWithContent, releaseSolePlugin, type PaneContent } from "$lib/workspace/documentPanes";
|
paneOf, showInActivePane, splitWithContent, releaseSolePlugin, dropInPane, resizeDocumentPanes, type PaneContent, type PaneDrop, type DocumentPanes } from "$lib/workspace/documentPanes";
|
||||||
import type { ViewMode } from "./ViewModes.svelte";
|
import type { ViewMode } from "./ViewModes.svelte";
|
||||||
import { selectedEditorText } from "$lib/editor/selection";
|
import { selectedEditorText } from "$lib/editor/selection";
|
||||||
import { pluginHost } from "$lib/plugins/registry";
|
import { pluginHost } from "$lib/plugins/registry";
|
||||||
@@ -267,29 +267,47 @@
|
|||||||
document.querySelector<HTMLElement>(`[data-document-pane="${paneId}"]`)?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
document.querySelector<HTMLElement>(`[data-document-pane="${paneId}"]`)?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function closeSplit(paneId: string) {
|
/** Use a new pane state and focus its active pane. The last pane does not keep a plugin view. The view covers the area again. */
|
||||||
const released = releaseSolePlugin(closeDocumentPane(documentPanes, paneId));
|
function changePanes(next: DocumentPanes) {
|
||||||
|
const released = releaseSolePlugin(next);
|
||||||
documentPanes = released.state;
|
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);
|
const view = $pluginEditors.find(view => view.key === released.pluginKey);
|
||||||
if (view) {
|
if (view) {
|
||||||
selectPluginEditor(view);
|
selectPluginEditor(view);
|
||||||
void tick().then(() => pluginPaneComponents[view.key]?.focus());
|
void tick().then(() => pluginPaneComponents[view.key]?.focus());
|
||||||
} else focusDocumentPane(documentPanes.active, true);
|
} else focusDocumentPane(documentPanes.active, true);
|
||||||
}
|
}
|
||||||
|
function closeSplit(paneId: string) {
|
||||||
|
changePanes(closeDocumentPane(documentPanes, paneId));
|
||||||
|
}
|
||||||
/** The plugin view that covers the document area moves into the active pane, so that a new pane can open beside it. */
|
/** The plugin view that covers the document area moves into the active pane, so that a new pane can open beside it. */
|
||||||
function keepCoverInPane() {
|
function keepCoverInPane() {
|
||||||
if (coverKey) documentPanes = showInActivePane(documentPanes, { pluginKey: coverKey });
|
if (coverKey) documentPanes = showInActivePane(documentPanes, { pluginKey: coverKey });
|
||||||
}
|
}
|
||||||
|
/** A plugin document that opens to the right, for example a PDF file: the source pane, and the plugin view that covers the area. */
|
||||||
|
let rightOf: { pane: string; cover: string | null } | null = null;
|
||||||
async function openToRight(file: TreeEntry, sourcePane: string) {
|
async function openToRight(file: TreeEntry, sourcePane: string) {
|
||||||
const current = documents;
|
const current = documents;
|
||||||
const covered = sourcePane === documentPanes.active ? coverKey : null;
|
const covered = sourcePane === documentPanes.active ? coverKey : null;
|
||||||
const source = documentPanes.panes.find(pane => pane.id === sourcePane);
|
const source = documentPanes.panes.find(pane => pane.id === sourcePane);
|
||||||
if (!current || switching || !source) return;
|
if (!current || switching || !source) return;
|
||||||
await current.open(file, "background");
|
const unchanged = () => {
|
||||||
const now = documentPanes.panes.find(pane => pane.id === sourcePane);
|
const now = documentPanes.panes.find(pane => pane.id === sourcePane);
|
||||||
if (documents !== current || switching || documentPanes.active !== sourcePane || coverKey !== covered
|
return documents === current && !switching && documentPanes.active === sourcePane && coverKey === covered
|
||||||
|| now?.documentId !== source.documentId || now?.pluginKey !== source.pluginKey) return;
|
&& now?.documentId === source.documentId && now?.pluginKey === source.pluginKey;
|
||||||
|
};
|
||||||
|
const open = current.buffers.find(tab => tab.relPath === file.rel_path);
|
||||||
|
if (!(open && open.contents !== open.saved)) {
|
||||||
|
// The placement effect opens the plugin view in a new pane beside the source pane.
|
||||||
|
rightOf = { pane: sourcePane, cover: covered };
|
||||||
|
try {
|
||||||
|
const opened = await openPluginDocument(file.rel_path, unchanged);
|
||||||
|
await tick();
|
||||||
|
if (opened) return;
|
||||||
|
} finally { rightOf = null; }
|
||||||
|
}
|
||||||
|
await current.open(file, "background");
|
||||||
|
if (!unchanged()) return;
|
||||||
const target = current.buffers.find(tab => tab.relPath === file.rel_path);
|
const target = current.buffers.find(tab => tab.relPath === file.rel_path);
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
keepCoverInPane();
|
keepCoverInPane();
|
||||||
@@ -311,8 +329,36 @@
|
|||||||
documentPanes = splitWithContent(documentPanes, documentPanes.active, tabContent(tab), crypto.randomUUID());
|
documentPanes = splitWithContent(documentPanes, documentPanes.active, tabContent(tab), crypto.randomUUID());
|
||||||
focusDocumentPane(documentPanes.active, true);
|
focusDocumentPane(documentPanes.active, true);
|
||||||
}
|
}
|
||||||
|
// A tab that the user drags from the tab bar to the document area: the pane and the place of the drop.
|
||||||
|
let documentArea: DocumentArea | undefined = $state();
|
||||||
|
let tabDrop = $state<{ pane: string; zone: PaneDrop } | null>(null);
|
||||||
|
function tabDropTarget(path: string, x: number, y: number) {
|
||||||
|
const tab = workingTabs.find(tab => tab.relPath === path);
|
||||||
|
const target = tab && !switching ? documentArea?.dropAt(x, y) ?? null : null;
|
||||||
|
if (!tab || !target) return null;
|
||||||
|
// A drop on the pane that shows the tab changes nothing.
|
||||||
|
if (coverKey ? "plugin" in tab && tab.plugin.key === coverKey : paneOf(documentPanes, tabContent(tab))?.id === target.pane) return null;
|
||||||
|
return { tab, target };
|
||||||
|
}
|
||||||
|
function tabDragAt(path: string, x: number, y: number) {
|
||||||
|
tabDrop = tabDropTarget(path, x, y)?.target ?? null;
|
||||||
|
return tabDrop !== null;
|
||||||
|
}
|
||||||
|
function tabDropAt(path: string, x: number, y: number) {
|
||||||
|
const found = tabDropTarget(path, x, y);
|
||||||
|
tabDrop = null;
|
||||||
|
if (!found) return false;
|
||||||
|
const { tab, target } = found;
|
||||||
|
if (coverKey) {
|
||||||
|
if (target.zone === "center") { selectWorkingTab(tab.relPath); return true; }
|
||||||
|
keepCoverInPane();
|
||||||
|
}
|
||||||
|
changePanes(dropInPane(documentPanes, tabContent(tab), target.pane, target.zone, crypto.randomUUID()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Each focused plugin view that is not in a pane gets a pane when the area has several panes.
|
// 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.
|
// A new view that a plugin opens beside its own view, for example a browser tab, opens beside the pane of that view.
|
||||||
|
// When the own view covers the area, it moves into the pane first.
|
||||||
const placedPlugins = new Set<string>();
|
const placedPlugins = new Set<string>();
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const view = $pluginEditorActive && $pluginView?.placement === "editor" ? $pluginView : null;
|
const view = $pluginEditorActive && $pluginView?.placement === "editor" ? $pluginView : null;
|
||||||
@@ -323,9 +369,19 @@
|
|||||||
placedPlugins.add(view.key);
|
placedPlugins.add(view.key);
|
||||||
const shown = paneOf(documentPanes, { pluginKey: view.key });
|
const shown = paneOf(documentPanes, { pluginKey: view.key });
|
||||||
if (shown) { documentPanes = selectPane(documentPanes, shown.id); return; }
|
if (shown) { documentPanes = selectPane(documentPanes, shown.id); return; }
|
||||||
if (documentPanes.panes.length < 2) return;
|
const right = rightOf;
|
||||||
|
if (right && documentPanes.panes.some(pane => pane.id === right.pane)) {
|
||||||
|
rightOf = null;
|
||||||
|
if (right.cover && right.cover !== view.key && !paneOf(documentPanes, { pluginKey: right.cover }))
|
||||||
|
documentPanes = showInActivePane(selectPane(documentPanes, right.pane), { pluginKey: right.cover });
|
||||||
|
documentPanes = splitWithContent(documentPanes, right.pane, { pluginKey: view.key }, crypto.randomUUID());
|
||||||
|
return;
|
||||||
|
}
|
||||||
const group = fresh ? splits.find(tree => containsPane(tree, view.key)) : undefined;
|
const group = fresh ? splits.find(tree => containsPane(tree, view.key)) : undefined;
|
||||||
const beside = group ? splitSibling(group, view.key) : null;
|
const beside = group ? splitSibling(group, view.key) : null;
|
||||||
|
if (documentPanes.panes.length < 2 && !beside) return;
|
||||||
|
if (beside && documentPanes.panes.length < 2 && !paneOf(documentPanes, { pluginKey: beside.sibling }))
|
||||||
|
documentPanes = showInActivePane(documentPanes, { pluginKey: beside.sibling });
|
||||||
const source = beside ? paneOf(documentPanes, { pluginKey: beside.sibling }) : undefined;
|
const source = beside ? paneOf(documentPanes, { pluginKey: beside.sibling }) : undefined;
|
||||||
documentPanes = source && beside
|
documentPanes = source && beside
|
||||||
? splitWithContent(documentPanes, source.id, { pluginKey: view.key }, crypto.randomUUID(), beside.direction)
|
? splitWithContent(documentPanes, source.id, { pluginKey: view.key }, crypto.randomUUID(), beside.direction)
|
||||||
@@ -438,9 +494,7 @@
|
|||||||
} catch (reason) { error = String(reason); }
|
} catch (reason) { error = String(reason); }
|
||||||
}
|
}
|
||||||
const activeTabPath = $derived(editorPluginVisible && $pluginView ? `plugin:${$pluginView.key}` : activePath);
|
const activeTabPath = $derived(editorPluginVisible && $pluginView ? `plugin:${$pluginView.key}` : activePath);
|
||||||
const activeSplit = $derived($pluginSplits.find(tree => $pluginView && containsPane(tree, $pluginView.key)));
|
// The working tabs of the header.
|
||||||
const pluginBounds = $derived(activeSplit ? paneBounds(activeSplit) : $pluginView ? paneBounds($pluginView.key) : {});
|
|
||||||
// The working tabs, for the header and for the tab bar of each plugin pane in a split.
|
|
||||||
const tabBarProps = $derived({ tabs: workingTabs, activePath: activeTabPath, onSelect: selectWorkingTab, onClose: closeTab,
|
const tabBarProps = $derived({ tabs: workingTabs, activePath: activeTabPath, onSelect: selectWorkingTab, onClose: closeTab,
|
||||||
onCloseTabs: (path: string, scope: TabCloseScope) => void closeTabs(path, scope), onPin: pinWorkingTab, fileActions: workingTabFileActions,
|
onCloseTabs: (path: string, scope: TabCloseScope) => void closeTabs(path, scope), onPin: pinWorkingTab, fileActions: workingTabFileActions,
|
||||||
tabActions: workingTabActions, onMove: moveWorkingTab, tabDragData: workingTabDragData, onDropTab: (data: string, index: number) => void receiveTab(data, index) });
|
tabActions: workingTabActions, onMove: moveWorkingTab, tabDragData: workingTabDragData, onDropTab: (data: string, index: number) => void receiveTab(data, index) });
|
||||||
@@ -1399,7 +1453,7 @@
|
|||||||
{leftView}
|
{leftView}
|
||||||
{sidebarNavigation}
|
{sidebarNavigation}
|
||||||
onSelectLeft={selectLeft}
|
onSelectLeft={selectLeft}
|
||||||
tabBar={{ ...tabBarProps, onDetach: (tab) => { void detachTab(tab); } }}
|
tabBar={{ ...tabBarProps, onDetach: (tab) => { void detachTab(tab); }, onDragAt: tabDragAt, onDropAt: tabDropAt, onDragEnd: () => { tabDrop = null; } }}
|
||||||
onNewTab={newTab}
|
onNewTab={newTab}
|
||||||
canOpenBrowser={!!browserContribution?.newTab}
|
canOpenBrowser={!!browserContribution?.newTab}
|
||||||
{browserOpening}
|
{browserOpening}
|
||||||
@@ -1429,6 +1483,7 @@
|
|||||||
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath}
|
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath}
|
||||||
{searchRequest}
|
{searchRequest}
|
||||||
onOpenFile={(entry, line, target) => void openFile(entry, line, target)}
|
onOpenFile={(entry, line, target) => void openFile(entry, line, target)}
|
||||||
|
onOpenRight={(entry) => void openToRight(entry, documentPanes.active)}
|
||||||
onCreated={(entry) => { void openCreatedFile(entry); }}
|
onCreated={(entry) => { void openCreatedFile(entry); }}
|
||||||
onSaveTemplate={(entry) => { void saveTemplate(entry); }}
|
onSaveTemplate={(entry) => { void saveTemplate(entry); }}
|
||||||
onManageTemplates={() => templateManager = true}
|
onManageTemplates={() => templateManager = true}
|
||||||
@@ -1455,12 +1510,12 @@
|
|||||||
|
|
||||||
<div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}>
|
<div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}>
|
||||||
<DocumentArea
|
<DocumentArea
|
||||||
|
bind:this={documentArea}
|
||||||
bind:pluginPaneComponents
|
bind:pluginPaneComponents
|
||||||
bind:paneComponents
|
bind:paneComponents
|
||||||
pluginCover={coverKey !== null}
|
pluginCover={coverKey !== null}
|
||||||
split={!!activeSplit}
|
drop={tabDrop}
|
||||||
{pluginBounds}
|
onResize={(path, ratio) => { documentPanes = resizeDocumentPanes(documentPanes, path, ratio); }}
|
||||||
tabBar={tabBarProps}
|
|
||||||
{documentViews}
|
{documentViews}
|
||||||
layout={documentPanes.layout}
|
layout={documentPanes.layout}
|
||||||
activePane={documentPanes.active}
|
activePane={documentPanes.active}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { paneBounds, removePane, splitPane, type SplitLayout } from "./splitLayout.ts";
|
import { paneBounds, removePane, setSplitRatio, splitPane, type SplitLayout, type SplitPath } from "./splitLayout.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pane shows one document or one plugin editor view, for example a browser tab. A pane never shows both.
|
* A pane shows one document or one plugin editor view, for example a browser tab. A pane never shows both.
|
||||||
@@ -106,6 +106,29 @@ export function releaseSolePlugin(state: DocumentPanes): { state: DocumentPanes;
|
|||||||
return { state: { ...state, panes: [{ ...pane, pluginKey: null }] }, pluginKey: pane.pluginKey };
|
return { state: { ...state, panes: [{ ...pane, pluginKey: null }] }, pluginKey: pane.pluginKey };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The place of a tab drop on a pane: the pane itself, or a new pane on its right or bottom side. */
|
||||||
|
export type PaneDrop = "center" | "right" | "down";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the content in the `target` pane (`center`), or in a new pane beside it.
|
||||||
|
* The content leaves the pane that showed it before, so that it shows in one pane only.
|
||||||
|
* The content that the drop replaces stays open as a tab.
|
||||||
|
*/
|
||||||
|
export function dropInPane(state: DocumentPanes, content: PaneContent, target: string, zone: PaneDrop, paneId: string): DocumentPanes {
|
||||||
|
if (!state.panes.some(pane => pane.id === target)) return state;
|
||||||
|
const current = paneOf(state, content);
|
||||||
|
if (current?.id === target) return selectPane(state, target);
|
||||||
|
const cleared = state.panes.map(pane => pane.id === current?.id ? emptyPane(pane.id) : pane);
|
||||||
|
if (zone === "center") return collapse(state, cleared.map(pane => pane.id === target ? filled(target, content) : pane), target);
|
||||||
|
return splitWithContent(collapse(state, cleared, target), target, content, paneId, zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Give a new ratio to a split between panes. */
|
||||||
|
export function resizeDocumentPanes(state: DocumentPanes, path: SplitPath, ratio: number): DocumentPanes {
|
||||||
|
const layout = setSplitRatio(state.layout, path, ratio);
|
||||||
|
return layout === state.layout ? state : { ...state, layout };
|
||||||
|
}
|
||||||
|
|
||||||
export function readDocumentPane(state: DocumentPanes, id: string, reading: boolean): DocumentPanes {
|
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) };
|
return { ...state, panes: state.panes.map(pane => pane.id === id ? { ...pane, reading, split: reading ? false : pane.split } : pane) };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
export type SplitLayout = string | { direction: "right" | "down"; first: SplitLayout; second: SplitLayout };
|
/** A split gives `ratio` of its size to `first`. A split without a ratio divides its size in two equal parts. */
|
||||||
|
export type SplitLayout = string | { direction: "right" | "down"; first: SplitLayout; second: SplitLayout; ratio?: number };
|
||||||
export type PaneBounds = { left: number; top: number; width: number; height: number };
|
export type PaneBounds = { left: number; top: number; width: number; height: number };
|
||||||
|
/** The path from the root to a split: the side of each split on the way. */
|
||||||
|
export type SplitPath = readonly ("first" | "second")[];
|
||||||
|
/** A divider between the two sides of a split. `bounds` is the area of the split, in percent of the root. */
|
||||||
|
export type SplitDivider = { path: SplitPath; direction: "right" | "down"; ratio: number; bounds: PaneBounds };
|
||||||
|
const ratioOf = (tree: Exclude<SplitLayout, string>) => tree.ratio ?? 0.5;
|
||||||
|
|
||||||
export function containsPane(tree: SplitLayout, key: string): boolean {
|
export function containsPane(tree: SplitLayout, key: string): boolean {
|
||||||
return typeof tree === "string" ? tree === key : containsPane(tree.first, key) || containsPane(tree.second, key);
|
return typeof tree === "string" ? tree === key : containsPane(tree.first, key) || containsPane(tree.second, key);
|
||||||
@@ -18,15 +24,40 @@ export function removePane(tree: SplitLayout, key: string): SplitLayout | null {
|
|||||||
|
|
||||||
export function paneBounds(tree: SplitLayout, bounds: PaneBounds = { left: 0, top: 0, width: 100, height: 100 }): Record<string, PaneBounds> {
|
export function paneBounds(tree: SplitLayout, bounds: PaneBounds = { left: 0, top: 0, width: 100, height: 100 }): Record<string, PaneBounds> {
|
||||||
if (typeof tree === "string") return { [tree]: bounds };
|
if (typeof tree === "string") return { [tree]: bounds };
|
||||||
const a = { ...bounds }, b = { ...bounds };
|
const [a, b] = sides(tree, bounds);
|
||||||
if (tree.direction === "right") { a.width /= 2; b.width /= 2; b.left += a.width; }
|
|
||||||
else { a.height /= 2; b.height /= 2; b.top += a.height; }
|
|
||||||
return { ...paneBounds(tree.first, a), ...paneBounds(tree.second, b) };
|
return { ...paneBounds(tree.first, a), ...paneBounds(tree.second, b) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sides(tree: Exclude<SplitLayout, string>, bounds: PaneBounds): [PaneBounds, PaneBounds] {
|
||||||
|
const a = { ...bounds }, b = { ...bounds }, ratio = ratioOf(tree);
|
||||||
|
if (tree.direction === "right") { a.width = bounds.width * ratio; b.width = bounds.width - a.width; b.left += a.width; }
|
||||||
|
else { a.height = bounds.height * ratio; b.height = bounds.height - a.height; b.top += a.height; }
|
||||||
|
return [a, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Each split of the tree, with its place, for the dividers that change its ratio. */
|
||||||
|
export function splitDividers(tree: SplitLayout, bounds: PaneBounds = { left: 0, top: 0, width: 100, height: 100 }, path: SplitPath = []): SplitDivider[] {
|
||||||
|
if (typeof tree === "string") return [];
|
||||||
|
const [a, b] = sides(tree, bounds);
|
||||||
|
return [{ path, direction: tree.direction, ratio: ratioOf(tree), bounds },
|
||||||
|
...splitDividers(tree.first, a, [...path, "first"]), ...splitDividers(tree.second, b, [...path, "second"])];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Give a new ratio to the split at `path`. The ratio stays between 0.1 and 0.9. */
|
||||||
|
export function setSplitRatio(tree: SplitLayout, path: SplitPath, ratio: number): SplitLayout {
|
||||||
|
if (typeof tree === "string" || !Number.isFinite(ratio)) return tree;
|
||||||
|
if (!path.length) {
|
||||||
|
const next = Math.round(Math.max(0.1, Math.min(0.9, ratio)) * 1000) / 1000;
|
||||||
|
return next === ratioOf(tree) ? tree : { ...tree, ratio: next };
|
||||||
|
}
|
||||||
|
const [side, ...rest] = path;
|
||||||
|
const child = setSplitRatio(tree[side], rest, ratio);
|
||||||
|
return child === tree[side] ? tree : { ...tree, [side]: child };
|
||||||
|
}
|
||||||
|
|
||||||
/** The same panes in the same order, one above the other. A narrow area uses it. */
|
/** The same panes in the same order, one above the other. A narrow area uses it. */
|
||||||
export function stackLayout(tree: SplitLayout): SplitLayout {
|
export function stackLayout(tree: SplitLayout): SplitLayout {
|
||||||
return typeof tree === "string" ? tree : { direction: "down", first: stackLayout(tree.first), second: stackLayout(tree.second) };
|
return typeof tree === "string" ? tree : { ...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. */
|
/** The direction of the split that put `key` beside a different pane, and the first pane on the other side. */
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Split view with different tabs: two documents side by side, a browser tab beside a document, a browser tab that covers
|
// 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.
|
// the area and then moves into a pane, the close control of a plugin pane, and the Read beside toggle, in both themes.
|
||||||
|
// Also the divider that resizes two panes, a tab that the user drags into a pane, and the new browser tab beside a browser tab.
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||||
@@ -19,7 +20,7 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
|
|||||||
...workspace,
|
...workspace,
|
||||||
browser_connect: () => "window-session",
|
browser_connect: () => "window-session",
|
||||||
browser_request: ({ command, args }) => {
|
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 === "newTab") { globalThis.newTabUrls = [...(globalThis.newTabUrls || []), args.url ?? null]; 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);
|
if (command === "closeTab") snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId);
|
||||||
return structuredClone(snapshot);
|
return structuredClone(snapshot);
|
||||||
},
|
},
|
||||||
@@ -35,6 +36,33 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
|
|||||||
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
|
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 box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
|
||||||
|
// A native tab drag: dragstart on the tab button, dragover at a place of the target, then the drop and dragend.
|
||||||
|
async function dragOver(source, target, where) {
|
||||||
|
const point = await target.evaluate((node, where) => {
|
||||||
|
const r = node.getBoundingClientRect();
|
||||||
|
return where === "down" ? { x: r.left + r.width / 2, y: r.bottom - 12 } : where === "right" ? { x: r.right - 12, y: r.top + r.height / 2 } : { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
||||||
|
}, where);
|
||||||
|
return source.evaluate((node, point) => {
|
||||||
|
const transfer = new DataTransfer();
|
||||||
|
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, cancelable: true, dataTransfer: transfer }));
|
||||||
|
const over = new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer });
|
||||||
|
document.elementFromPoint(point.x, point.y).dispatchEvent(over);
|
||||||
|
globalThis.tabDrag = { node, transfer, point };
|
||||||
|
return over.defaultPrevented;
|
||||||
|
}, point);
|
||||||
|
}
|
||||||
|
async function drop() {
|
||||||
|
return page.evaluate(() => {
|
||||||
|
const { node, transfer, point } = globalThis.tabDrag;
|
||||||
|
const event = new DragEvent("drop", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer });
|
||||||
|
document.elementFromPoint(point.x, point.y).dispatchEvent(event);
|
||||||
|
node.dispatchEvent(new DragEvent("dragend", { bubbles: true, clientX: point.x, clientY: point.y, dataTransfer: transfer }));
|
||||||
|
return event.defaultPrevented;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function setMode(mode) {
|
||||||
|
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
|
||||||
|
}
|
||||||
async function newBrowserTab() {
|
async function newBrowserTab() {
|
||||||
await page.evaluate(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); await pluginHost.get("browser").newTab(); });
|
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.locator('[data-browser-state="ready"]').last().waitFor();
|
||||||
@@ -102,5 +130,73 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
|
|||||||
await pane("b.md").locator(".cm-content").waitFor();
|
await pane("b.md").locator(".cm-content").waitFor();
|
||||||
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
|
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
|
||||||
await pane("b.md").locator(".md-page").waitFor();
|
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));
|
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
|
||||||
|
|
||||||
|
// The divider between two panes changes their sizes, with the pointer and with the keyboard.
|
||||||
|
await openToRight("a.md");
|
||||||
|
await pane("a.md").locator(".cm-content").waitFor();
|
||||||
|
const divider = page.getByRole("separator", { name: "Resize panes" });
|
||||||
|
assert.equal(await divider.count(), 1);
|
||||||
|
const area = await box(page.locator(".center"));
|
||||||
|
const handle = await box(divider);
|
||||||
|
await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(handle.x + handle.width / 2 - area.width * 0.2, handle.y + handle.height / 2, { steps: 4 });
|
||||||
|
await page.mouse.up();
|
||||||
|
const narrow = await box(pane("b.md")), wide = await box(pane("a.md"));
|
||||||
|
assert.ok(Math.abs(narrow.width - area.width * 0.3) < 4, `The left pane has 30% of the area: ${narrow.width} of ${area.width}`);
|
||||||
|
assert.ok(Math.abs(wide.x - (narrow.x + narrow.width)) < 2, "The right pane starts at the divider");
|
||||||
|
assert.equal(await divider.getAttribute("aria-valuenow"), "30");
|
||||||
|
await divider.focus(); await page.keyboard.press("ArrowRight");
|
||||||
|
assert.equal(await divider.getAttribute("aria-valuenow"), "35");
|
||||||
|
for (const mode of ["light", "dark"]) {
|
||||||
|
await setMode(mode);
|
||||||
|
await divider.hover();
|
||||||
|
await page.screenshot({ path: path.join(output, `divider-${mode}.png`) });
|
||||||
|
}
|
||||||
|
await divider.dblclick();
|
||||||
|
assert.equal(await divider.getAttribute("aria-valuenow"), "50");
|
||||||
|
|
||||||
|
// A new browser tab replaces the document in the focused pane. A document tab dragged to the bottom of the browser pane
|
||||||
|
// opens below it.
|
||||||
|
await newBrowserTab();
|
||||||
|
assert.equal(await pane("a.md").count(), 0);
|
||||||
|
assert.equal(await dragOver(tab("a.md"), browserPane, "down"), true, "The browser pane takes the tab");
|
||||||
|
await page.locator('.drop-hint[data-drop-zone="down"]').waitFor();
|
||||||
|
for (const mode of ["light", "dark"]) {
|
||||||
|
await setMode(mode);
|
||||||
|
await page.screenshot({ path: path.join(output, `tab-drop-${mode}.png`) });
|
||||||
|
}
|
||||||
|
assert.equal(await drop(), true);
|
||||||
|
await pane("a.md").locator(".cm-content").waitFor();
|
||||||
|
assert.equal(await page.locator(".drop-hint").count(), 0);
|
||||||
|
const web = await box(browserPane), below = await box(pane("a.md"));
|
||||||
|
assert.ok(below.y >= web.y + web.height - 1 && Math.abs(below.x - web.x) < 2, "The document shows below the browser");
|
||||||
|
assert.equal(await page.getByRole("separator", { name: "Resize panes" }).count(), 2);
|
||||||
|
// The browser tab dragged to the document pane replaces it there, and leaves its old pane. The first browser tab is not visible.
|
||||||
|
assert.equal(await dragOver(tab("Browser").last(), pane("b.md"), "center"), true);
|
||||||
|
assert.equal(await drop(), true);
|
||||||
|
await page.waitForFunction(() => document.querySelectorAll(".document-pane").length === 2);
|
||||||
|
assert.equal(await pane("b.md").count(), 0);
|
||||||
|
assert.equal(await tab("b.md").count(), 1, "The replaced document stays open as a tab");
|
||||||
|
const moved = await box(browserPane), rest = await box(pane("a.md"));
|
||||||
|
assert.ok(rest.x >= moved.x + moved.width - 1, "The browser shows left of the document");
|
||||||
|
// A drop on the pane that shows the tab changes nothing.
|
||||||
|
assert.equal(await dragOver(tab("Browser").last(), browserPane, "center"), false);
|
||||||
|
await drop();
|
||||||
|
|
||||||
|
// "New tab to the right" of a browser tab that covers the area opens a new browser tab beside it, not a copy of the page.
|
||||||
|
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
|
||||||
|
await browserPane.waitFor();
|
||||||
|
assert.ok((await box(browserPane)).width > area.width - 4, "The browser covers the area");
|
||||||
|
const before = await page.evaluate(() => globalThis.newTabUrls.length);
|
||||||
|
await tab("Browser").last().click({ button: "right" });
|
||||||
|
await page.getByRole("menuitem", { name: "New tab to the right", exact: true }).click();
|
||||||
|
await page.waitForFunction(() => document.querySelectorAll(".plugin-pane.embedded:not(.inactive)").length === 2);
|
||||||
|
assert.deepEqual(await page.evaluate(start => globalThis.newTabUrls.slice(start), before), [null], "The new tab opens the home page");
|
||||||
|
const [first, second] = await page.locator(".plugin-pane.embedded:not(.inactive)").evaluateAll(nodes => nodes.map(node => { const r = node.getBoundingClientRect(); return { x: r.x, width: r.width }; }).sort((a, b) => a.x - b.x));
|
||||||
|
assert.ok(second.x >= first.x + first.width - 1 && first.width > area.width * 0.4, "The browser tabs show side by side");
|
||||||
|
await page.screenshot({ path: path.join(output, "browser-beside-browser.png") });
|
||||||
|
|
||||||
|
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", "divider by pointer, keyboard, and double-click", "tab drop below a pane", "tab drop replaces a pane", "new browser tab beside a browser tab", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
|
||||||
}, { timeout: 30000 });
|
}, { timeout: 30000 });
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ await runSmoke("layout/panesAndSettings", async ({ browser }) => {
|
|||||||
const menu = page.getByRole("menu", { name: "File actions", exact: true });
|
const menu = page.getByRole("menu", { name: "File actions", exact: true });
|
||||||
await menu.waitFor();
|
await menu.waitFor();
|
||||||
const labels = await menu.locator(":scope > button, :scope > hr").evaluateAll(nodes => nodes.map(node => node.tagName === "HR" ? "|" : node.querySelector(".action-label").textContent));
|
const labels = await menu.locator(":scope > button, :scope > hr").evaluateAll(nodes => nodes.map(node => node.tagName === "HR" ? "|" : node.querySelector(".action-label").textContent));
|
||||||
assert.deepEqual(labels, ["Open in new tab", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
|
assert.deepEqual(labels, ["Open in new tab", "Open to the right", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
|
||||||
"Rename", "Remove bookmark", "Pin", "Save as template", "|", "Show in Explorer", "Copy path", "|", "Undo file move", "Redo file move", "|", "Delete", "Delete permanently"]);
|
"Rename", "Remove bookmark", "Pin", "Save as template", "|", "Show in Explorer", "Copy path", "|", "Undo file move", "Redo file move", "|", "Delete", "Delete permanently"]);
|
||||||
const error = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-error)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
|
const error = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-error)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
|
||||||
assert.equal(await menu.getByRole("menuitem", { name: "Delete", exact: true }).evaluate(node => getComputedStyle(node).color), error);
|
assert.equal(await menu.getByRole("menuitem", { name: "Delete", exact: true }).evaluate(node => getComputedStyle(node).color), error);
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// A PDF file beside a note: "Open to the right" in the file tree opens the PDF in a new pane beside the note.
|
||||||
|
// The user writes in the note and turns the pages of the PDF, and both panes stay visible. A drag of the divider resizes
|
||||||
|
// both panes. A PDF that covers the area moves into the left pane when a note opens to its right. Both themes.
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import path from "node:path";
|
||||||
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||||
|
import { samplePdf } from "../../fixtures/pdf/fixtures.mjs";
|
||||||
|
|
||||||
|
await runSmoke("layout/pdfBesideNote", async ({ page }) => {
|
||||||
|
const output = await outputDir("layout/pdfBesideNote");
|
||||||
|
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
||||||
|
await mockTauri(page, {
|
||||||
|
state: { sample: [...samplePdf()] },
|
||||||
|
commands: test => ({
|
||||||
|
...test.workspace({ root: "C:\\pdf-beside-note", files: { "Sample.pdf": "", "note.md": "# Note\n\nReading notes.\n" } }),
|
||||||
|
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||||
|
spelling_menu_install: () => null,
|
||||||
|
workspace_read_bytes: () => new Uint8Array(test.state.sample).buffer,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = name => page.locator(`[data-tree-rel="${name}"]`);
|
||||||
|
const note = page.locator('[data-document-path="note.md"]');
|
||||||
|
const pdf = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator(".pdf-viewer") });
|
||||||
|
const status = pdf.locator(".pdf-viewer .status");
|
||||||
|
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
|
||||||
|
async function besideEachOther(left, right, message) {
|
||||||
|
const a = await box(left), b = await box(right);
|
||||||
|
assert.ok(b.x >= a.x + a.width - 1 && Math.abs(a.y - b.y) < 2, message);
|
||||||
|
return [a, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.goto(smokeUrl);
|
||||||
|
await row("note.md").click();
|
||||||
|
await note.locator(".cm-content").waitFor();
|
||||||
|
|
||||||
|
// The file tree opens the PDF in a new pane to the right of the note.
|
||||||
|
await row("Sample.pdf").click({ button: "right" });
|
||||||
|
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
|
||||||
|
await status.filter({ hasText: /^Page 1 of 2$/ }).waitFor();
|
||||||
|
assert.equal(await page.locator(".document-pane").count(), 2);
|
||||||
|
await besideEachOther(note, pdf, "The PDF shows to the right of the note");
|
||||||
|
|
||||||
|
// Write in the note. The PDF stays visible.
|
||||||
|
await note.locator(".cm-content").click();
|
||||||
|
await page.keyboard.press("Control+End");
|
||||||
|
await page.keyboard.type("Typed beside the PDF.");
|
||||||
|
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./);
|
||||||
|
assert.equal(await pdf.count(), 1);
|
||||||
|
// Turn a page of the PDF. The note stays visible and keeps the text.
|
||||||
|
await pdf.getByRole("button", { name: "Next page", exact: true }).click();
|
||||||
|
await status.filter({ hasText: /^Page 2 of 2$/ }).waitFor();
|
||||||
|
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./);
|
||||||
|
// Back to the note: the keyboard goes to the note.
|
||||||
|
await note.locator(".cm-content").click();
|
||||||
|
await page.keyboard.type(" More.");
|
||||||
|
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\. More\./);
|
||||||
|
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("note.md"));
|
||||||
|
|
||||||
|
// The divider gives the PDF more space.
|
||||||
|
const divider = page.getByRole("separator", { name: "Resize panes" });
|
||||||
|
const handle = await box(divider), area = await box(page.locator(".center"));
|
||||||
|
await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(handle.x + handle.width / 2 - area.width * 0.15, handle.y + handle.height / 2, { steps: 4 });
|
||||||
|
await page.mouse.up();
|
||||||
|
const [left, right] = await besideEachOther(note, pdf, "The panes stay side by side after a resize");
|
||||||
|
assert.ok(right.width > left.width + area.width * 0.2, "The PDF pane is wider than the note pane");
|
||||||
|
for (const mode of ["light", "dark"]) {
|
||||||
|
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
|
||||||
|
await page.screenshot({ path: path.join(output, `pdf-beside-note-${mode}.png`) });
|
||||||
|
}
|
||||||
|
|
||||||
|
// A PDF that covers the area moves into the left pane when a note opens to its right.
|
||||||
|
await pdf.getByRole("button", { name: "Close split", exact: true }).click();
|
||||||
|
await page.getByRole("tab", { name: /Sample/ }).click();
|
||||||
|
await status.waitFor();
|
||||||
|
assert.ok((await box(pdf)).width > area.width - 4, "The PDF covers the area");
|
||||||
|
await row("note.md").click({ button: "right" });
|
||||||
|
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
|
||||||
|
await note.locator(".cm-content").waitFor();
|
||||||
|
await besideEachOther(pdf, note, "The PDF keeps the left pane");
|
||||||
|
console.log(JSON.stringify({ passed: ["file tree opens a PDF to the right", "typing in the note beside the PDF", "page turn in the PDF beside the note", "divider resize", "covering PDF moves into a pane", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
|
||||||
|
}, { timeout: 30000 });
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { test } from "node:test";
|
import { test } from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin } from "../../../src/lib/workspace/documentPanes.ts";
|
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin, dropInPane, resizeDocumentPanes } from "../../../src/lib/workspace/documentPanes.ts";
|
||||||
import { paneBounds, splitSibling, stackLayout } from "../../../src/lib/workspace/splitLayout.ts";
|
import { paneBounds, splitDividers, splitSibling, stackLayout, setSplitRatio } from "../../../src/lib/workspace/splitLayout.ts";
|
||||||
import { registerSelection, selectedEditorText } from "../../../src/lib/editor/selection.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", () => {
|
test("opening a link to the right keeps its source and focuses an existing pane for duplicate targets", () => {
|
||||||
@@ -112,3 +112,45 @@ test("the split sibling names the pane that a plugin view opened beside", () =>
|
|||||||
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
|
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
|
||||||
assert.equal(splitSibling("a", "a"), null);
|
assert.equal(splitSibling("a", "a"), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a divider changes the ratio of its split, within limits, and the narrow layout keeps the ratio", () => {
|
||||||
|
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
|
||||||
|
state = splitDocumentPane(state, state.active, "b", "right");
|
||||||
|
state = splitWithContent(state, "right", { documentId: "c" }, "low", "down");
|
||||||
|
const dividers = splitDividers(state.layout);
|
||||||
|
assert.deepEqual(dividers.map(divider => [divider.path.join("/"), divider.direction, divider.ratio]), [["", "right", 0.5], ["second", "down", 0.5]]);
|
||||||
|
state = resizeDocumentPanes(state, [], 0.3);
|
||||||
|
state = resizeDocumentPanes(state, ["second"], 0.75);
|
||||||
|
const bounds = paneBounds(state.layout);
|
||||||
|
assert.equal(bounds["document-main"].width, 30);
|
||||||
|
assert.deepEqual(bounds.right, { left: 30, top: 0, width: 70, height: 75 });
|
||||||
|
assert.equal(bounds.low.top, 75);
|
||||||
|
assert.equal(paneBounds(stackLayout(state.layout))["document-main"].height, 30);
|
||||||
|
assert.equal(paneBounds(resizeDocumentPanes(state, [], 0.02).layout)["document-main"].width, 10, "A pane keeps a tenth of the split at least");
|
||||||
|
assert.equal(setSplitRatio("only", [], 0.4), "only");
|
||||||
|
assert.equal(resizeDocumentPanes(state, ["second", "first"], 0.4), state, "A path to a pane changes nothing");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a tab drop replaces the content of a pane or opens a pane beside it, and the content leaves its old pane", () => {
|
||||||
|
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
|
||||||
|
const main = state.active;
|
||||||
|
state = splitWithContent(state, main, { pluginKey: "web" }, "right");
|
||||||
|
// A document dropped in the browser pane replaces the browser there. The browser stays open as a tab.
|
||||||
|
let next = dropInPane(state, { documentId: "b" }, "right", "center", "new");
|
||||||
|
assert.deepEqual(next.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], ["b", null]]);
|
||||||
|
assert.equal(next.active, "right");
|
||||||
|
// A drop on the bottom side of a pane opens a new pane there.
|
||||||
|
next = dropInPane(state, { documentId: "c" }, main, "down", "new");
|
||||||
|
assert.deepEqual(paneBounds(next.layout).new, { left: 0, top: 50, width: 50, height: 50 });
|
||||||
|
assert.equal(next.active, "new");
|
||||||
|
// A visible tab moves: its old pane closes.
|
||||||
|
next = dropInPane(state, { pluginKey: "web" }, main, "down", "new");
|
||||||
|
assert.deepEqual(next.panes.map(pane => [pane.id, pane.pluginKey]), [[main, null], ["new", "web"]]);
|
||||||
|
assert.deepEqual(paneBounds(next.layout).new, { left: 0, top: 50, width: 100, height: 50 });
|
||||||
|
next = dropInPane(state, { pluginKey: "web" }, main, "center", "new");
|
||||||
|
assert.deepEqual(next.panes.map(pane => pane.pluginKey), ["web"]);
|
||||||
|
// A drop on the pane that shows the content only makes it active.
|
||||||
|
assert.equal(dropInPane(state, { pluginKey: "web" }, "right", "down", "new").panes.length, 2);
|
||||||
|
assert.equal(dropInPane(state, { documentId: "a" }, "missing", "center", "new"), state);
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user