RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin, dropInPane, moveToNewPane, 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", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
|
||||
const primary = state.active;
|
||||
state = readDocumentPane(state, primary, true);
|
||||
state = splitDocumentPane(state, primary, "b", "right");
|
||||
assert.deepEqual(state.panes.map(pane => pane.documentId), ["a", "b"]);
|
||||
assert.equal(state.active, "right");
|
||||
assert.deepEqual(paneBounds(state.layout).right, { left: 50, top: 0, width: 50, height: 100 });
|
||||
state = splitDocumentPane(state, "right", "a", "unused");
|
||||
assert.equal(state.active, primary);
|
||||
assert.equal(state.panes.length, 2);
|
||||
assert.equal(state.panes[0].reading, true);
|
||||
state = splitDocumentPane(state, "right", "c", "third");
|
||||
assert.equal(paneBounds(state.layout).third.left, 75);
|
||||
});
|
||||
|
||||
test("Read and Split exclude each other, and a closed document resets both", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
||||
const pane = state.active;
|
||||
state = splitDocumentView(state, pane, true);
|
||||
assert.deepEqual([state.panes[0].reading, state.panes[0].split], [false, true]);
|
||||
state = readDocumentPane(state, pane, true);
|
||||
assert.deepEqual([state.panes[0].reading, state.panes[0].split], [true, false]);
|
||||
state = splitDocumentView(state, pane, true);
|
||||
assert.deepEqual([state.panes[0].reading, state.panes[0].split], [false, true]);
|
||||
// Write and Source keep the Split view.
|
||||
state = readDocumentPane(state, pane, false);
|
||||
assert.equal(state.panes[0].split, true);
|
||||
state = syncDocumentPanes(state, ["b"], "b");
|
||||
assert.deepEqual([state.panes[0].documentId, state.panes[0].reading, state.panes[0].split], ["b", false, false]);
|
||||
});
|
||||
|
||||
test("closing a split preserves the remaining pane and a later tab selection can restore its hidden document", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
||||
state = splitDocumentPane(state, state.active, "b", "right");
|
||||
state = closeDocumentPane(state, "right");
|
||||
assert.equal(state.panes[0].documentId, "a");
|
||||
assert.equal(state.layout, state.active);
|
||||
state = syncDocumentPanes(state, ["a", "b"], "b");
|
||||
assert.equal(state.panes[0].documentId, "b");
|
||||
});
|
||||
|
||||
test("tab replacement stays in its focused pane, and closing another tab collapses only its empty pane", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
||||
state = splitDocumentPane(state, state.active, "b", "right");
|
||||
state = syncDocumentPanes(state, ["a", "c"], "c");
|
||||
assert.deepEqual(state.panes.map(pane => pane.documentId), ["a", "c"]);
|
||||
assert.equal(state.active, "right");
|
||||
const unchanged = syncDocumentPanes(state, ["a", "c"], "c");
|
||||
assert.equal(unchanged, state);
|
||||
state = syncDocumentPanes(state, ["c"], "c");
|
||||
assert.equal(state.panes.length, 1);
|
||||
assert.equal(state.layout, "right");
|
||||
assert.equal(selectPane(state, "missing"), state);
|
||||
});
|
||||
|
||||
test("selection readers remain available in both panes and disposal cannot clear a replacement reader", () => {
|
||||
const first = registerSelection("a", () => "first selection");
|
||||
const second = registerSelection("b", () => "second selection");
|
||||
assert.equal(selectedEditorText("a"), "first selection");
|
||||
assert.equal(selectedEditorText("b"), "second selection");
|
||||
const replacement = registerSelection("a", () => "new selection");
|
||||
first(); second();
|
||||
assert.equal(selectedEditorText("a"), "new selection");
|
||||
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);
|
||||
});
|
||||
|
||||
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 drop on the left side of a pane opens a new pane before it.
|
||||
next = dropInPane(state, { documentId: "c" }, "right", "left", "new");
|
||||
assert.deepEqual(paneBounds(next.layout), { [main]: { left: 0, top: 0, width: 50, height: 100 }, new: { left: 50, top: 0, width: 25, height: 100 }, right: { left: 75, top: 0, width: 25, height: 100 } });
|
||||
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);
|
||||
});
|
||||
|
||||
test("the content of a pane moves to a new pane beside it, and the pane shows other content", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
|
||||
const main = state.active;
|
||||
state = readDocumentPane(state, main, true);
|
||||
// The visible document moves to the right. Its pane shows the next document, in the default view.
|
||||
let next = moveToNewPane(state, main, { documentId: "b" }, { documentId: "a" }, "right", "new");
|
||||
assert.deepEqual(next.panes.map(pane => [pane.id, pane.documentId, pane.reading]), [[main, "b", false], ["new", "a", false]]);
|
||||
assert.deepEqual(paneBounds(next.layout).new, { left: 50, top: 0, width: 50, height: 100 });
|
||||
assert.equal(next.active, "new");
|
||||
// A plugin view that covers the area moves below. The pane keeps its document and its view.
|
||||
next = moveToNewPane(state, main, { documentId: "a" }, { pluginKey: "web" }, "down", "new");
|
||||
assert.deepEqual(next.panes.map(pane => [pane.documentId, pane.pluginKey, pane.reading]), [["a", null, true], [null, "web", false]]);
|
||||
assert.deepEqual(paneBounds(next.layout).new, { left: 0, top: 50, width: 100, height: 50 });
|
||||
// The visible document moves to a new pane on the left.
|
||||
next = moveToNewPane(state, main, { documentId: "b" }, { documentId: "a" }, "left", "new");
|
||||
assert.deepEqual(next.panes.map(pane => [pane.id, pane.documentId]), [[main, "b"], ["new", "a"]]);
|
||||
assert.deepEqual(paneBounds(next.layout), { new: { left: 0, top: 0, width: 50, height: 100 }, [main]: { left: 50, top: 0, width: 50, height: 100 } });
|
||||
next = moveToNewPane(state, main, { documentId: "a" }, { pluginKey: "web" }, "down", "new");
|
||||
// Content that a different pane shows cannot stay, and cannot move from this pane.
|
||||
assert.equal(moveToNewPane(next, main, { pluginKey: "web" }, { documentId: "a" }, "right", "third"), next);
|
||||
assert.equal(moveToNewPane(next, main, { documentId: "b" }, { pluginKey: "web" }, "right", "third"), next);
|
||||
assert.equal(moveToNewPane(state, "missing", { documentId: "b" }, { documentId: "a" }, "right", "new"), state);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { DEFAULT_SETTINGS, SETTINGS_KEY, normalizeSettings, parseSettings, readSettings, saveSettings } from "../../../src/lib/workspace/settings.ts";
|
||||
|
||||
test("missing or damaged preferences keep safe defaults", () => {
|
||||
for (const raw of [null, "{broken", "null", "[]", "42", '"text"']) {
|
||||
assert.deepEqual(parseSettings(raw), DEFAULT_SETTINGS);
|
||||
}
|
||||
for (const autosaveSeconds of [0, -1, 301, 1.5, "10", null]) {
|
||||
assert.deepEqual(parseSettings(JSON.stringify({ autosaveEnabled: false, autosaveSeconds, showInternalFolder: false })), { autosaveEnabled: false, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true, showFileTitle: true, keepLineBreaks: false });
|
||||
}
|
||||
assert.deepEqual(parseSettings('{"autosaveEnabled":"false","autosaveSeconds":10}'), { autosaveEnabled: true, autosaveSeconds: 10, showInternalFolder: false, tableFormulas: true, showFileTitle: true, keepLineBreaks: false });
|
||||
});
|
||||
|
||||
function withStorage(storage: Pick<Storage, "getItem" | "setItem">, body: () => void) {
|
||||
const prior = globalThis.localStorage;
|
||||
try { globalThis.localStorage = storage as Storage; body(); }
|
||||
finally { globalThis.localStorage = prior; }
|
||||
}
|
||||
|
||||
test("preferences persist and load at both interval limits", () => {
|
||||
const store = new Map<string, string>();
|
||||
withStorage({ getItem: (key: string) => store.get(key) ?? null, setItem: (key: string, value: string) => { store.set(key, value); } }, () => {
|
||||
for (const autosaveSeconds of [1, 23, 300]) {
|
||||
const settings = { autosaveEnabled: false, autosaveSeconds, showInternalFolder: false, tableFormulas: autosaveSeconds !== 23, showFileTitle: autosaveSeconds !== 300, keepLineBreaks: autosaveSeconds === 1 };
|
||||
void saveSettings(settings);
|
||||
assert.deepEqual(parseSettings(store.get(SETTINGS_KEY)!), settings);
|
||||
assert.deepEqual(readSettings(), settings);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("invalid changes never reach storage and storage failures reach the caller", () => {
|
||||
let writes = 0;
|
||||
withStorage({ getItem: () => null, setItem: () => { writes++; } }, () => {
|
||||
for (const autosaveSeconds of [NaN, Infinity, 0, 301, 2.5]) {
|
||||
assert.throws(() => saveSettings({ autosaveEnabled: true, autosaveSeconds, showInternalFolder: false, tableFormulas: true, showFileTitle: true, keepLineBreaks: false }));
|
||||
}
|
||||
});
|
||||
assert.equal(writes, 0);
|
||||
withStorage({ getItem: () => null, setItem: () => { throw new Error("Storage unavailable"); } }, () => {
|
||||
assert.throws(() => saveSettings({ ...DEFAULT_SETTINGS }), /Storage unavailable/);
|
||||
});
|
||||
});
|
||||
|
||||
test("stored values of any type normalize to safe settings", () => {
|
||||
for (const value of [undefined, null, 42, "text", [], { autosaveSeconds: 0 }]) assert.deepEqual(normalizeSettings(value), DEFAULT_SETTINGS);
|
||||
assert.deepEqual(normalizeSettings({ autosaveEnabled: false, autosaveSeconds: 9, showInternalFolder: true }), { autosaveEnabled: false, autosaveSeconds: 9, showInternalFolder: true, tableFormulas: true, showFileTitle: true, keepLineBreaks: false });
|
||||
assert.equal(normalizeSettings({ tableFormulas: false }).tableFormulas, false);
|
||||
for (const tableFormulas of [null, 0, "false", {}]) assert.equal(normalizeSettings({ tableFormulas }).tableFormulas, true);
|
||||
assert.equal(normalizeSettings({ showFileTitle: false }).showFileTitle, false);
|
||||
for (const showFileTitle of [null, 0, "false", {}]) assert.equal(normalizeSettings({ showFileTitle }).showFileTitle, true);
|
||||
assert.equal(normalizeSettings({ keepLineBreaks: true }).keepLineBreaks, true);
|
||||
for (const keepLineBreaks of [null, 1, "true", {}]) assert.equal(normalizeSettings({ keepLineBreaks }).keepLineBreaks, false);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { splitPane, removePane, paneBounds, containsPane } from "../../../src/lib/workspace/splitLayout.ts";
|
||||
|
||||
test("nested splits preserve the source and divide the requested pane", () => {
|
||||
const right = splitPane("a", "a", "b", "right");
|
||||
const nested = splitPane(right, "b", "c", "down");
|
||||
assert.deepEqual(paneBounds(nested), {
|
||||
a: { left: 0, top: 0, width: 50, height: 100 },
|
||||
b: { left: 50, top: 0, width: 50, height: 50 },
|
||||
c: { left: 50, top: 50, width: 50, height: 50 },
|
||||
});
|
||||
assert.equal(containsPane(nested, "c"), true);
|
||||
const closed = removePane(nested, "b")!;
|
||||
assert.deepEqual(paneBounds(closed).c, { left: 50, top: 0, width: 50, height: 100 });
|
||||
assert.equal(removePane(closed, "a"), "c");
|
||||
assert.equal(removePane("c", "c"), null);
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { tabsToClose } from "../../../src/lib/workspace/tabActions.ts";
|
||||
import { Documents } from "../../../src/lib/workspace/documents.svelte.ts";
|
||||
|
||||
function setup() {
|
||||
return new Documents({
|
||||
read: async () => "original", write: async () => {}, image: async () => "data:image/png;base64,",
|
||||
kind: () => "text", chrome: () => "Writing",
|
||||
}, () => {});
|
||||
}
|
||||
const entry = (path: string) => ({ rel_path: path, name: path, kind: "file" as const });
|
||||
|
||||
test("group closes follow tab order and preserve pins without changing the active tab", async () => {
|
||||
const docs = setup();
|
||||
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await docs.open(entry(name));
|
||||
docs.togglePin("b.md");
|
||||
docs.move("d.md", 1);
|
||||
const paths = (scope: "one" | "others" | "after" | "all") => tabsToClose(docs.buffers, "d.md", scope).map(tab => tab.relPath);
|
||||
assert.deepEqual(paths("one"), ["d.md"]);
|
||||
assert.deepEqual(paths("others"), ["a.md", "c.md"]);
|
||||
assert.deepEqual(paths("after"), ["c.md"]);
|
||||
assert.deepEqual(paths("all"), ["a.md", "d.md", "c.md"]);
|
||||
assert.equal(docs.activePath, "d.md");
|
||||
assert.deepEqual(tabsToClose(docs.buffers, "missing.md", "all"), []);
|
||||
assert.equal(tabsToClose(docs.buffers, "b.md", "one")[0].pinned, true);
|
||||
});
|
||||
|
||||
test("pinning protects current and empty tabs from replacement, and survives rename", async () => {
|
||||
const docs = setup();
|
||||
await docs.open(entry("a.md"));
|
||||
docs.togglePin("a.md");
|
||||
await docs.open(entry("b.md"), "current");
|
||||
assert.deepEqual(docs.buffers.map(tab => tab.relPath), ["a.md", "b.md"]);
|
||||
docs.rename("a.md", "renamed.md");
|
||||
assert.equal(docs.buffers[0].pinned, true);
|
||||
docs.newTab();
|
||||
const blank = docs.active!;
|
||||
docs.togglePin(blank.relPath);
|
||||
await docs.open(entry("c.md"));
|
||||
assert.ok(docs.buffers.includes(blank));
|
||||
docs.select("renamed.md");
|
||||
docs.togglePin("renamed.md");
|
||||
await docs.open(entry("d.md"), "current");
|
||||
assert.ok(!docs.buffers.some(tab => tab.relPath === "renamed.md"));
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { COMMAND_LABELS, commandShortcut, preferenceKeys, workbenchCommand, workbenchKeys } from "../../../src/lib/layout/workbenchKeys.ts";
|
||||
import { shortcutLabel } from "../../../src/lib/ui/shortcuts.ts";
|
||||
|
||||
const press = (key: string, modifiers: { ctrl?: boolean; meta?: boolean; shift?: boolean; alt?: boolean } = {}, code?: string) =>
|
||||
({ key, code, ctrlKey: !!modifiers.ctrl, metaKey: !!modifiers.meta, shiftKey: !!modifiers.shift, altKey: !!modifiers.alt, target: null });
|
||||
|
||||
test("main shortcuts accept Ctrl and Cmd and keep their shift rules", () => {
|
||||
assert.equal(workbenchCommand(press("p", { ctrl: true })), "quick-open");
|
||||
assert.equal(workbenchCommand(press("P", { meta: true, shift: true })), "command-palette");
|
||||
assert.equal(workbenchCommand(press("P", { ctrl: true, shift: true })), "command-palette");
|
||||
assert.equal(workbenchCommand(press("t", { ctrl: true })), "new-tab");
|
||||
assert.equal(workbenchCommand(press("T", { ctrl: true, shift: true })), null);
|
||||
assert.equal(workbenchCommand(press("F", { ctrl: true, shift: true })), "search-workspace");
|
||||
assert.equal(workbenchCommand(press("f", { ctrl: true })), null, "Ctrl+F belongs to the document");
|
||||
assert.equal(workbenchCommand(press("`", { ctrl: true })), "toggle-terminal");
|
||||
});
|
||||
|
||||
test("Ctrl+B belongs to the editor, and Ctrl+\\ toggles the side pane on every layout", () => {
|
||||
assert.equal(workbenchCommand(press("b", { ctrl: true })), null);
|
||||
assert.equal(workbenchCommand(press("\\", { ctrl: true }, "Backslash")), "toggle-sidebar");
|
||||
assert.equal(workbenchCommand(press("#", { ctrl: true }, "Backslash")), "toggle-sidebar", "The physical key matches on other layouts");
|
||||
});
|
||||
|
||||
test("Each command has a label, and its shortcut label comes from the table", () => {
|
||||
for (const binding of [...workbenchKeys, ...preferenceKeys]) assert.ok(COMMAND_LABELS[binding.command], binding.command);
|
||||
assert.equal(commandShortcut("save"), shortcutLabel({ key: "s", mod: true }));
|
||||
});
|
||||
|
||||
test("F2 renames outside text fields only", () => {
|
||||
assert.equal(workbenchCommand(press("F2")), "rename");
|
||||
assert.equal(workbenchCommand(press("F2", { alt: true })), null);
|
||||
assert.equal(workbenchCommand(press("F2", { ctrl: true })), null);
|
||||
});
|
||||
|
||||
test("preference shortcuts switch tabs with Ctrl only and open Settings and Help", () => {
|
||||
assert.equal(workbenchCommand(press("Tab", { ctrl: true }), preferenceKeys), "next-tab");
|
||||
assert.equal(workbenchCommand(press("Tab", { ctrl: true, shift: true }), preferenceKeys), "previous-tab");
|
||||
assert.equal(workbenchCommand(press("Tab", { meta: true }), preferenceKeys), null);
|
||||
assert.equal(workbenchCommand(press(",", { meta: true }), preferenceKeys), "settings");
|
||||
assert.equal(workbenchCommand(press("F1"), preferenceKeys), "help");
|
||||
assert.equal(workbenchCommand(press("F1", { shift: true }), preferenceKeys), null);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout } from "../../../src/lib/workspace/workbenchLayout.ts";
|
||||
|
||||
test("missing and damaged layouts use defaults", () => {
|
||||
for (const raw of [null, "{broken", "null", "[]", "42", '"text"']) {
|
||||
assert.deepEqual(parseWorkbenchLayout(raw), DEFAULT_WORKBENCH_LAYOUT);
|
||||
}
|
||||
});
|
||||
|
||||
test("invalid layout fields do not discard valid collapsed states", () => {
|
||||
for (const leftWidth of [0, -1, 159, 481, "260", null]) {
|
||||
assert.deepEqual(parseWorkbenchLayout(JSON.stringify({ leftOpen: false, rightOpen: false, leftWidth, rightWidth: 320, leftView: "unknown", backlinksOpen: "false" })), {
|
||||
...DEFAULT_WORKBENCH_LAYOUT, leftOpen: false, rightOpen: false, rightWidth: 320,
|
||||
});
|
||||
}
|
||||
assert.deepEqual(parseWorkbenchLayout('{"leftOpen":"false","rightOpen":0}'), DEFAULT_WORKBENCH_LAYOUT);
|
||||
// A layout from an older version has no backlinks field. The section starts expanded.
|
||||
assert.equal(parseWorkbenchLayout('{"leftOpen":false}').backlinksOpen, true);
|
||||
});
|
||||
|
||||
test("layout survives storage round trips with hidden panels, all navigation views, and collapsed backlinks", () => {
|
||||
const store = new Map<string, string>();
|
||||
for (const leftView of ["files", "search", "bookmarks"] as const) {
|
||||
for (const [leftWidth, backlinksOpen] of [[160, false], [321.5, true], [480, false]] as const) {
|
||||
const layout = { leftOpen: false, rightOpen: false, leftWidth, rightWidth: 400, leftView, backlinksOpen };
|
||||
saveWorkbenchLayout({ setItem: (key, value) => { store.set(key, value); } }, layout);
|
||||
assert.deepEqual(parseWorkbenchLayout(store.get(WORKBENCH_LAYOUT_KEY)!), layout);
|
||||
}
|
||||
}
|
||||
assert.throws(() => saveWorkbenchLayout({ setItem: () => { throw new Error("Storage unavailable"); } }, { ...DEFAULT_WORKBENCH_LAYOUT }), /Storage unavailable/);
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { orderWorkbenchTabs } from "../../../src/lib/workspace/workbenchTabs.ts";
|
||||
import { tabsToClose } from "../../../src/lib/workspace/tabActions.ts";
|
||||
import { Documents } from "../../../src/lib/workspace/documents.svelte.ts";
|
||||
|
||||
test("mixed tabs retain their positions through title changes, closes, and new tabs", () => {
|
||||
const tabs = [
|
||||
{ id: "a", relPath: "a.md", name: "a.md", pinned: true },
|
||||
{ id: "b", relPath: "renamed.md", name: "renamed.md" },
|
||||
{ id: "plugin-a", relPath: "plugin:a", name: "New page title" },
|
||||
{ id: "plugin-b", relPath: "plugin:b", name: "Board" },
|
||||
];
|
||||
const ordered = orderWorkbenchTabs(tabs, ["plugin-a", "b", "a", "closed", "plugin-a"]);
|
||||
assert.deepEqual(ordered.map(tab => tab.id), ["plugin-a", "b", "a", "plugin-b"]);
|
||||
assert.equal(ordered[0].name, "New page title");
|
||||
assert.deepEqual(tabsToClose(ordered, "plugin:a", "after").map(tab => tab.id), ["b", "plugin-b"]);
|
||||
assert.deepEqual(tabsToClose(ordered, "renamed.md", "others").map(tab => tab.id), ["plugin-a", "plugin-b"]);
|
||||
assert.deepEqual(tabsToClose(ordered, "plugin:b", "all").map(tab => tab.id), ["plugin-a", "b", "plugin-b"]);
|
||||
});
|
||||
|
||||
test("replacing an empty or current document retains its tab position and creates a new buffer", async () => {
|
||||
const docs = new Documents({
|
||||
read: async path => path, write: async () => {}, image: async () => "",
|
||||
kind: () => "text", chrome: () => "Writing",
|
||||
}, () => {});
|
||||
docs.newTab();
|
||||
const emptyId = docs.active!.id;
|
||||
const order = ["plugin-a", emptyId, "plugin-b"];
|
||||
for (const rel_path of ["a.md", "b.md"]) {
|
||||
const previousBuffer = docs.active!.id;
|
||||
await docs.open({ rel_path, name: rel_path, kind: "file" }, "current");
|
||||
assert.notEqual(docs.active!.id, previousBuffer);
|
||||
assert.equal(docs.active!.tabId, emptyId);
|
||||
const tabs = [{ id: "plugin-a" }, { id: "plugin-b" }, { id: docs.active!.tabId! }];
|
||||
assert.deepEqual(orderWorkbenchTabs(tabs, order).map(tab => tab.id), order);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user