RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-16 04:21:21 -07:00
commit b52eeb14a1
827 changed files with 241421 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import assert from "node:assert/strict";
import test from "node:test";
import { actionEntries, selectionRoots, setSelectedMarks, runTreeActions } from "../../../src/lib/workspace/treeActions.ts";
import { planDrop } from "../../../src/lib/workspace/treeDrop.ts";
import type { TreeEntry } from "../../../src/lib/workspace/types.ts";
const entry = (rel_path: string, kind: "file" | "folder" = "file"): TreeEntry => ({ rel_path, name: rel_path.split("/").pop()!, kind });
const entries = [entry("notes", "folder"), entry("notes/a.md"), entry("notes/sub", "folder"), entry("notes/sub/b.md"), entry("notes-old/c.md"), entry("z.md")];
const visible = entries.map(item => item.rel_path);
const find = (path: string) => entries.find(item => item.rel_path === path) ?? null;
test("context actions use all selected visible rows in display order", () => {
assert.deepEqual(actionEntries(entries[1], new Set(["z.md", "missing", "notes/a.md"]), visible, find), [entries[1], entries[5]]);
assert.deepEqual(actionEntries(entries[0], new Set(["z.md", "notes/a.md"]), visible, find), [entries[0]]);
});
test("recursive actions process each selected folder once without including similar names", () => {
assert.deepEqual(selectionRoots([...entries].reverse()), [entries[5], entries[4], entries[0]]);
assert.deepEqual(selectionRoots(entries.slice(1)), [entries[1], entries[2], entries[4], entries[5]]);
});
test("mixed marks become uniformly enabled or disabled and preserve other marks", () => {
const current = ["outside.md", "notes/a.md"];
const selection = [entries[1], entries[5]];
assert.deepEqual(setSelectedMarks(current, selection, true), ["outside.md", "notes/a.md", "z.md"]);
assert.deepEqual(setSelectedMarks(current, selection, false), ["outside.md"]);
assert.deepEqual(current, ["outside.md", "notes/a.md"]);
});
test("a failed action does not skip later items or lose successful results", async () => {
const visited: string[] = [];
const result = await runTreeActions(entries, async item => {
visited.push(item.rel_path);
if (item === entries[1]) throw new Error("Access denied");
return item.name;
});
assert.deepEqual(visited, visible);
assert.deepEqual(result.completed.map(item => item.entry), entries.filter(item => item !== entries[1]));
assert.deepEqual(result.failures, ["notes/a.md: Access denied"]);
});
test("moving beside an existing same-name file preserves both files in the destination order", () => {
const plan = planDrop("notes/a.md", entry("a.md"), "after", parent => parent === "notes" ? ["a.md"] : ["a.md", "z.md"]);
assert.equal(plan.action, "move");
if (plan.action === "move") {
assert.equal(plan.to, "a 2.md");
assert.deepEqual(plan.orderTo, ["a.md", "a 2.md", "z.md"]);
}
assert.deepEqual(planDrop("notes", entries[1], "before", () => []), { action: "noop" });
});
+120
View File
@@ -0,0 +1,120 @@
import assert from "node:assert/strict";
import test from "node:test";
import { dropHint, dropPlaceAt, planDrop, uniqueName } from "../../../src/lib/workspace/treeDrop.ts";
function kids(map: Record<string, string[]>) {
return (parent: string) => map[parent] ?? [];
}
test("same-folder drop before a sibling reorders and keeps the name", () => {
const plan = planDrop(
"notes/b.md",
{ name: "a.md", rel_path: "notes/a.md", kind: "file" },
"before",
kids({ notes: ["a.md", "b.md"] }),
);
assert.deepEqual(plan, {
action: "reorder",
parent: "notes",
names: ["b.md", "a.md"],
});
});
test("same-folder drop after a sibling inserts after that sibling", () => {
const plan = planDrop(
"notes/a.md",
{ name: "b.md", rel_path: "notes/b.md", kind: "file" },
"after",
kids({ notes: ["a.md", "b.md"] }),
);
assert.deepEqual(plan, {
action: "reorder",
parent: "notes",
names: ["b.md", "a.md"],
});
});
test("drop inside the parent folder is a no-op", () => {
const plan = planDrop(
"notes/a.md",
{ name: "notes", rel_path: "notes", kind: "folder" },
"inside",
kids({ notes: ["a.md", "b.md"], "": ["notes"] }),
);
assert.deepEqual(plan, { action: "noop" });
});
test("drop before a sibling folder reorders instead of moving inside", () => {
const plan = planDrop(
"inbox.md",
{ name: "notes", rel_path: "notes", kind: "folder" },
"before",
kids({ "": ["inbox.md", "notes"] }),
);
assert.deepEqual(plan, {
action: "reorder",
parent: "",
names: ["inbox.md", "notes"],
});
});
test("drop onto self is a no-op", () => {
const plan = planDrop(
"notes/a.md",
{ name: "a.md", rel_path: "notes/a.md", kind: "file" },
"before",
kids({ notes: ["a.md"] }),
);
assert.deepEqual(plan, { action: "noop" });
});
test("drop inside another folder moves under that folder", () => {
const plan = planDrop(
"inbox.md",
{ name: "notes", rel_path: "notes", kind: "folder" },
"inside",
kids({ "": ["inbox.md", "notes"], notes: ["a.md"] }),
);
assert.deepEqual(plan, {
action: "move",
from: "inbox.md",
to: "notes/inbox.md",
fromParent: "",
toParent: "notes",
destName: "inbox.md",
orderFrom: ["notes"],
orderTo: ["a.md", "inbox.md"],
});
});
test("drop into a folder that already has the name picks a unique name", () => {
const plan = planDrop(
"inbox.md",
{ name: "notes", rel_path: "notes", kind: "folder" },
"inside",
kids({ "": ["inbox.md", "notes"], notes: ["inbox.md"] }),
);
assert.equal(plan.action, "move");
if (plan.action === "move") {
assert.equal(plan.to, "notes/inbox 2.md");
assert.equal(plan.destName, "inbox 2.md");
}
});
test("uniqueName skips taken numbered suffixes", () => {
assert.equal(uniqueName(["alpha.md", "alpha 2.md"], "alpha.md"), "alpha 3.md");
});
test("dropPlaceAt splits a file row in half and a folder row into three bands", () => {
assert.equal(dropPlaceAt("file", 0.2), "before");
assert.equal(dropPlaceAt("file", 0.8), "after");
assert.equal(dropPlaceAt("folder", 0.1), "before");
assert.equal(dropPlaceAt("folder", 0.5), "inside");
assert.equal(dropPlaceAt("folder", 0.9), "after");
});
test("dropHint names the landing", () => {
assert.equal(dropHint("notes", "inside"), "Into notes");
assert.equal(dropHint("inbox.md", "before"), "Before inbox.md");
assert.equal(dropHint("inbox.md", "after"), "After inbox.md");
});
+20
View File
@@ -0,0 +1,20 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { moveMarks, replayMoveMarks } from "../../../src/lib/workspace/treeMoveHistory.ts";
test("move undo preserves later bookmarks, pins, and new files", () => {
const before = { pins: ["notes/a.md"], bookmarks: [], order: { notes: ["a.md", "b.md"], archive: [] as string[] } };
const after = moveMarks(before, "notes/a.md", "archive/a.md");
const current = { ...after, bookmarks: ["other.md"], pins: [...after.pins, "b.md"], order: { ...after.order, notes: [...after.order.notes, "new.md"] } };
const undo = replayMoveMarks(current, before, after, [{ from: "notes/a.md", to: "archive/a.md" }], false);
assert.deepEqual(undo.pins, ["notes/a.md", "b.md"]);
assert.deepEqual(undo.bookmarks, ["other.md"]);
assert.deepEqual(undo.order.notes, ["a.md", "b.md", "new.md"]);
assert.deepEqual(undo.order.archive, []);
});
test("folder moves retain nested marks and custom order", () => {
const marks = { pins: ["old/child.md"], bookmarks: ["old/deep/file.md"], order: { old: ["child.md"], "old/deep": ["file.md"] } };
const next = moveMarks(marks, "old", "new/old");
assert.deepEqual(next.pins, ["new/old/child.md"]);
assert.deepEqual(next.bookmarks, ["new/old/deep/file.md"]);
assert.deepEqual(next.order["new/old/deep"], ["file.md"]);
});
+87
View File
@@ -0,0 +1,87 @@
import assert from "node:assert/strict";
import test from "node:test";
import { selectTreePath, treeSelectionEdges, visibleTreePaths, type TreeSelection } from "../../../src/lib/workspace/treeSelection.ts";
import type { TreeEntry } from "../../../src/lib/workspace/types.ts";
const entry = (rel_path: string, kind: "file" | "folder" = "file"): TreeEntry => ({ rel_path, name: rel_path.split("/").pop()!, kind });
const children = {
"": [entry("notes", "folder"), entry("src", "folder"), entry("z.md")],
notes: [entry("notes/b.md"), entry("notes/a.md"), entry("notes/nested", "folder")],
"notes/nested": [entry("notes/nested/c.md")],
src: [entry("src/main.ts")],
};
const visible = visibleTreePaths(children, new Set(["notes", "notes/nested"]));
const empty = (): TreeSelection => ({ paths: new Set(), anchor: null });
test("selection outlines omit shared edges and close around gaps and single rows", () => {
const rows = ["a.md", "b.md", "c.md", "d.md", "e.md"];
assert.deepEqual([...treeSelectionEdges(rows, new Set(["a.md", "b.md", "c.md", "e.md"]))], [
["a.md", { top: null, bottom: 0 }],
["b.md", { top: 0, bottom: 0 }],
["c.md", { top: 0, bottom: null }],
["e.md", { top: null, bottom: null }],
]);
assert.deepEqual([...treeSelectionEdges(rows, new Set(["a.md", "c.md", "e.md"]))].map(([, edges]) => edges),
Array.from({ length: 3 }, () => ({ top: null, bottom: null })));
});
test("nested selection outlines retain only exposed indentation steps in visible order", () => {
const edges = treeSelectionEdges(visible, new Set(visible));
assert.deepEqual(edges.get("notes"), { top: null, bottom: 1 });
assert.deepEqual(edges.get("notes/b.md"), { top: 0, bottom: 0 });
assert.deepEqual(edges.get("notes/nested"), { top: 0, bottom: 1 });
assert.deepEqual(edges.get("notes/nested/c.md"), { top: 0, bottom: 0 });
assert.deepEqual(edges.get("src"), { top: 2, bottom: 0 });
assert.deepEqual(edges.get("z.md"), { top: 0, bottom: null });
const collapsed = visibleTreePaths(children, new Set());
assert.deepEqual([...treeSelectionEdges(collapsed, new Set(visible))], [
["notes", { top: null, bottom: 0 }], ["src", { top: 0, bottom: 0 }], ["z.md", { top: 0, bottom: null }],
]);
});
test("visible order preserves custom sorting and only visits expanded folders", () => {
assert.deepEqual(visible, ["notes", "notes/b.md", "notes/a.md", "notes/nested", "notes/nested/c.md", "src", "z.md"]);
assert.deepEqual(visibleTreePaths(children, new Set()), ["notes", "src", "z.md"]);
});
test("Ctrl-click toggles files and folders independently; plain click replaces the selection", () => {
const first = selectTreePath(empty(), "notes", visible);
const added = selectTreePath(first, "z.md", visible, { ctrlKey: true });
assert.deepEqual([...added.paths], ["notes", "z.md"]);
assert.deepEqual([...first.paths], ["notes"]);
const removed = selectTreePath(added, "notes", visible, { ctrlKey: true });
assert.deepEqual([...removed.paths], ["z.md"]);
assert.deepEqual([...selectTreePath(removed, "z.md", visible, { ctrlKey: true }).paths], []);
assert.deepEqual([...selectTreePath(added, "src", visible).paths], ["src"]);
});
test("Shift-click selects an inclusive range in both directions across files and folders", () => {
const first = selectTreePath(empty(), "notes/b.md", visible);
const forward = selectTreePath(first, "src", visible, { shiftKey: true });
assert.deepEqual([...forward.paths], visible.slice(1, 6));
const reverse = selectTreePath(selectTreePath(empty(), "src", visible), "notes/b.md", visible, { shiftKey: true });
assert.deepEqual([...reverse.paths], visible.slice(1, 6));
});
test("repeated Shift-click keeps the anchor and shrinks or reverses the range", () => {
const first = selectTreePath(empty(), "notes/a.md", visible);
const extended = selectTreePath(first, "z.md", visible, { shiftKey: true });
const shrunk = selectTreePath(extended, "notes/nested", visible, { shiftKey: true });
assert.deepEqual([...shrunk.paths], ["notes/a.md", "notes/nested"]);
assert.equal(shrunk.anchor, "notes/a.md");
assert.deepEqual([...selectTreePath(shrunk, "notes", visible, { shiftKey: true }).paths], visible.slice(0, 3));
});
test("Ctrl+Shift adds a range and Command-click supports the same toggle behavior", () => {
let selection = selectTreePath(empty(), "z.md", visible);
selection = selectTreePath(selection, "notes/b.md", visible, { metaKey: true });
selection = selectTreePath(selection, "notes/nested", visible, { ctrlKey: true, shiftKey: true });
assert.deepEqual([...selection.paths], ["z.md", "notes/b.md", "notes/a.md", "notes/nested"]);
assert.deepEqual([...selectTreePath(selection, "z.md", visible, { metaKey: true }).paths], ["notes/b.md", "notes/a.md", "notes/nested"]);
});
test("a missing or hidden anchor makes Shift-click select only the clicked row", () => {
assert.deepEqual(selectTreePath(empty(), "src", visible, { shiftKey: true }), { paths: new Set(["src"]), anchor: "src" });
const hidden = selectTreePath(empty(), "notes/b.md", visible);
assert.deepEqual(selectTreePath(hidden, "z.md", ["notes", "src", "z.md"], { shiftKey: true }), { paths: new Set(["z.md"]), anchor: "z.md" });
});