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:
@@ -1,7 +1,7 @@
|
||||
import { test } from "node:test";
|
||||
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 { paneBounds, splitSibling, stackLayout } from "../../../src/lib/workspace/splitLayout.ts";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin, dropInPane, resizeDocumentPanes } from "../../../src/lib/workspace/documentPanes.ts";
|
||||
import { paneBounds, splitDividers, splitSibling, stackLayout, setSplitRatio } 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", () => {
|
||||
@@ -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.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