Show different tabs side by side in split view
Each tab menu has "Open to the right". It shows the tab in a new pane to the right of the active pane. A pane shows a document or a plugin tab, for example a browser tab. - A plugin view stays in the plugin layer above the panes, so a move between panes does not mount it again. - A browser tab that covers the area moves to the left pane when a tab opens beside it. The last pane gives its plugin tab the whole area. - The "Split" toggle of a document is now "Read beside". Card 565874b2.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView } from "../../../src/lib/workspace/documentPanes.ts";
|
||||
import { paneBounds } from "../../../src/lib/workspace/splitLayout.ts";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin } from "../../../src/lib/workspace/documentPanes.ts";
|
||||
import { paneBounds, splitSibling, stackLayout } from "../../../src/lib/workspace/splitLayout.ts";
|
||||
import { registerSelection, selectedEditorText } from "../../../src/lib/editor/selection.ts";
|
||||
|
||||
test("opening a link to the right keeps its source and focuses an existing pane for duplicate targets", () => {
|
||||
@@ -71,3 +71,44 @@ test("selection readers remain available in both panes and disposal cannot clear
|
||||
assert.equal(selectedEditorText("b"), "");
|
||||
replacement();
|
||||
});
|
||||
|
||||
test("a pane shows a document or a plugin view, and each tab has at most one pane", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
||||
const primary = state.active;
|
||||
state = splitWithContent(state, primary, { pluginKey: "browser" }, "web");
|
||||
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], [null, "browser"]]);
|
||||
assert.equal(state.active, "web");
|
||||
assert.equal(splitWithContent(state, primary, { pluginKey: "browser" }, "again"), selectPane(state, "web"));
|
||||
// A document change does not remove the plugin pane.
|
||||
assert.equal(syncDocumentPanes(state, ["a", "b"], null), state);
|
||||
// A selected document replaces the view of the active pane. The view stays open as a tab.
|
||||
const replaced = syncDocumentPanes(state, ["a", "b"], "b");
|
||||
assert.deepEqual(replaced.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], ["b", null]]);
|
||||
// A plugin view replaces the document of the active pane, and a shown document selects its pane.
|
||||
state = showInActivePane(selectPane(replaced, primary), { pluginKey: "board" });
|
||||
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [[null, "board"], ["b", null]]);
|
||||
assert.equal(showInActivePane(state, { documentId: "b" }).active, "web");
|
||||
assert.equal(paneOf(state, { pluginKey: "board" })?.id, primary);
|
||||
});
|
||||
|
||||
test("a closed plugin view leaves its pane, and the last pane gives its plugin view back to the whole area", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a"], "a");
|
||||
state = splitWithContent(state, state.active, { pluginKey: "browser" }, "web", "down");
|
||||
assert.deepEqual(paneBounds(state.layout).web, { left: 0, top: 50, width: 100, height: 50 });
|
||||
assert.deepEqual(paneBounds(stackLayout({ direction: "right", first: "x", second: "y" })).y, { left: 0, top: 50, width: 100, height: 50 });
|
||||
const closed = syncDocumentPanes(state, ["a"], null, []);
|
||||
assert.deepEqual(closed.panes.map(pane => pane.id), ["document-main"]);
|
||||
const remaining = closeDocumentPane(state, "document-main");
|
||||
assert.equal(remaining.active, "web");
|
||||
const released = releaseSolePlugin(remaining);
|
||||
assert.equal(released.pluginKey, "browser");
|
||||
assert.deepEqual([released.state.panes[0].documentId, released.state.panes[0].pluginKey], [null, null]);
|
||||
assert.equal(releaseSolePlugin(closed).state, closed);
|
||||
});
|
||||
|
||||
test("the split sibling names the pane that a plugin view opened beside", () => {
|
||||
const tree = { direction: "right" as const, first: "a", second: { direction: "down" as const, first: "b", second: "c" } };
|
||||
assert.deepEqual(splitSibling(tree, "c"), { direction: "down", sibling: "b" });
|
||||
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
|
||||
assert.equal(splitSibling("a", "a"), null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user