Clear references leaves the pinned references alone

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw9fjYBYFyV8YG5YDfYPRb
This commit is contained in:
Claude
2026-11-02 14:17:26 +00:00
parent a63b8a1c33
commit 8a99ee2686
4 changed files with 10 additions and 12 deletions
+2 -2
View File
@@ -40,7 +40,7 @@ test("the selected scene's references are marked on their tiles, and the menu ta
const flag = (n) => [...named(n).querySelectorAll(".cx-cell-flag")].map((x) => x.textContent).join();
assert.deepEqual([flag("dog.png"), flag("cat.png"), flag("owl.png")], ["R1", "R2", "📌R3"]);
const clear = [...host.querySelectorAll("button")].find((b) => b.textContent.startsWith("Clear references"));
assert.ok(clear && !clear.hidden && /\(3\)/.test(clear.textContent), "counts every picture used in any scene, pinned ones too");
assert.ok(clear && !clear.hidden && /\(2\)/.test(clear.textContent), "counts every picture in any scene's own list; pins are not counted");
document.querySelectorAll(".cx-popover").forEach((n) => n.remove());
named("dog.png").dispatchEvent(new window.MouseEvent("contextmenu", { bubbles: true, cancelable: true }));
const stop = [...document.querySelectorAll(".cx-menu-item")].find((b) => b.textContent.includes("Stop using as a reference"));
@@ -48,7 +48,7 @@ test("the selected scene's references are marked on their tiles, and the menu ta
stop.click();
assert.deepEqual(set, [["s1", "references", ["m1"]]]);
clear.click();
assert.deepEqual([doc.scenes.map((x) => x.references), doc.fixed_references], [[[], []], {}], "one click takes them off every scene and unpins");
assert.deepEqual([doc.scenes.map((x) => x.references), doc.fixed_references], [[[], []], { m3: 3 }], "one click empties every scene's list; the pin stays");
});
test("a changed pin repaints the slot numbers on the tiles even when the list of references is the same", async () => {
+1 -1
View File
@@ -149,7 +149,7 @@ export default {
} });
const controls = { sort, view: view, cols: tileSize };
bulk.node.hidden = true;
const clearRefs = c.button.sm({ label: "Clear references", tone: "ghost", title: "Stop using every reference picture in every scene, pinned ones too", onClick: () => p.edit(clearReferences) });
const clearRefs = c.button.sm({ label: "Clear references", tone: "ghost", title: "Stop using every reference picture in every scene (pinned ones stay)", onClick: () => p.edit(clearReferences) });
host.append(c.toolbar.default({ items: [c.text.sm({ text: "Media" })], trailing: [clearRefs, selectBtn, bulk] }).node, drop.node, note.node, seg("Show", FILTERS, "filter").node, sort.node,
view.node, tileSize.node, shelf.node);
+3 -5
View File
@@ -18,17 +18,15 @@ export function addScene(p, sourceType = "carry") {
return sc;
}
/** Every picture used as a reference anywhere in the project: each scene's own and the pinned ones (which go to every scene). */
/** Every picture in any scene's own reference list. The pinned ones (project.fixed_references) are a separate setting and are not counted. */
export function allReferences(p) {
return new Set([...Object.keys(p.fixed_references || {}), ...(p.scenes || []).flatMap((s) => s.references || [])]);
return new Set((p.scenes || []).flatMap((s) => s.references || []));
}
/** Stop using any reference picture in the whole project: every scene's list and the pins. -> how many pictures were in use (0: nothing changed). */
/** Empty every scene's own reference list; the pins stay. -> how many pictures were in use (0: nothing changed). */
export function clearReferences(p) {
const n = allReferences(p).size;
if (!n) return 0;
for (const s of p.scenes || []) if ((s.references || []).length) s.references = [];
p.fixed_references = {};
return n;
}
+4 -4
View File
@@ -87,10 +87,10 @@ test("removing the first cut of a unit hands its takes to the clip that becomes
assert.deepEqual(Object.keys(p.scene_variants), ["b"]);
});
test("clearReferences empties every scene and the pins, and says how many pictures were in use", async () => {
test("clearReferences empties every scene's own list, keeps the pins, and says how many pictures were in use", async () => {
const { clearReferences, allReferences } = await import("../edits.js");
const p = { fixed_references: { a: 1 }, scenes: [{ id: "x", references: ["b", "c"] }, { id: "y", references: ["b"] }, { id: "z" }] };
assert.equal(allReferences(p).size, 3);
assert.equal(clearReferences(p), 3);
assert.deepEqual([p.scenes.map((s) => s.references || []), p.fixed_references, clearReferences(p)], [[[], [], []], {}, 0]);
assert.equal(allReferences(p).size, 2);
assert.equal(clearReferences(p), 2);
assert.deepEqual([p.scenes.map((s) => s.references || []), p.fixed_references, clearReferences(p)], [[[], [], []], { a: 1 }, 0]);
});