Improve workspace navigation, search, and tab actions
This commit is contained in:
@@ -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.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"));
|
||||
});
|
||||
Reference in New Issue
Block a user