Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Allow duplicating references

Bitti4adf3cd57a71
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 1616a8f..fde2f39 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -4,6 +4,7 @@ This alpha update adds DMAD LoRA support, resumable model downloads, and improve
## What's new
+- Duplicate references from their context menu, including multiple selected references with their prompts, attachments, and media settings.
- Create a video scene with an image as its first frame, or create an image reference, directly from the Image tab's image bar context menu.
- Every project now includes Video and Image tabs. Older video and image projects keep their saved content, and Export supports both output types.
- Clothes and Accessories reference categories include common wearable items. Clothes offer optional color and fabric settings.
diff --git a/src/components/workspace/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsx
index ff47599..39f63ed 100644
--- a/src/components/workspace/ReferencesView.test.tsx
+++ b/src/components/workspace/ReferencesView.test.tsx
@@ -514,6 +514,59 @@ describe("Reference library views and selection", () => {
expect(open).toHaveBeenCalledWith(initial.generationJobs[0].id);
});
+ it.each(["Icons", "Details"])("duplicates the context-menu target with independently editable attachments in %s view", async (view) => {
+ const initial = three();
+ const source = initial.references[2];
+ Object.assign(source, {
+ subcategory: "Lighting",
+ iconRelativePath: "references/lamp-icon.png",
+ images: [{ id: "lamp-image", name: "Lamp image", relativePath: "references/lamp.png" }],
+ refmods: [{ id: "lamp-refmod", name: "Lamp refmod", sourcePath: "C:\\models\\lamp.refmod", strength: 0.7, copies: 2 }],
+ });
+ const state = setup(initial);
+ fireEvent.click(screen.getByRole("button", { name: view }));
+ // Opening an unselected item's menu must duplicate that item, not the inspector's selection.
+ const role = view === "Icons" ? "option" : "row";
+ fireEvent.contextMenu(screen.getByRole(role, { name: /^Lamp / }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Duplicate" }));
+
+ const copy = state.latest().references[3];
+ expect(copy).toEqual({ ...source, id: expect.any(String), name: "Lamp copy", createdAt: expect.any(String) });
+ expect(copy.id).not.toBe(source.id);
+ expect(copy.images).not.toBe(source.images);
+ expect(copy.refmods![0]).not.toBe(source.refmods![0]);
+ expect(copy.intendedUse).not.toBe(source.intendedUse);
+ expect(state.latest().generationJobs).toEqual(initial.generationJobs);
+ expect(state.latest().imageScene).toEqual(initial.imageScene);
+ expect(screen.getByRole("textbox", { name: "Reference name" })).toHaveValue("Lamp copy");
+ const tile = screen.getByRole(role, { name: /^Lamp copy / });
+ expect(tile).toHaveAttribute("aria-selected", "true");
+ await waitFor(() => expect(tile).toHaveFocus());
+ fireEvent.change(screen.getByRole("spinbutton", { name: "Lamp refmod strength" }), { target: { value: "0.4" } });
+ expect(state.latest().references[3].refmods![0].strength).toBe(0.4);
+ expect(state.latest().references[2].refmods![0].strength).toBe(0.7);
+ expect(parseProjectConfig(JSON.parse(JSON.stringify(state.latest()))).references).toEqual(state.latest().references);
+ });
+
+ it("duplicates a selection from the keyboard context menu and gives repeated copies unique names", () => {
+ const state = setup(three());
+ const hero = () => screen.getByRole("option", { name: /^Hero Text/ });
+ fireEvent.contextMenu(hero());
+ fireEvent.click(screen.getByRole("menuitem", { name: "Duplicate" }));
+ fireEvent.click(hero());
+ fireEvent.click(screen.getByRole("option", { name: /^Cat / }), { ctrlKey: true });
+ fireEvent.keyDown(hero(), { key: "ContextMenu" });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Duplicate 2 references" }));
+
+ expect(state.latest().references.map((reference) => reference.name)).toEqual([
+ "Hero", "Hero copy 2", "Hero copy", "Cat", "Cat copy", "Lamp",
+ ]);
+ const ids = state.latest().references.map((reference) => reference.id);
+ expect(new Set(ids).size).toBe(ids.length);
+ expect(screen.getAllByRole("option", { selected: true }).map((option) => option.textContent)).toEqual(["Hero copy 2", "Cat copy"]);
+ expect(screen.getByRole("region", { name: "References status" })).toHaveTextContent("2 selected");
+ });
+
it("shows the shared empty state when nothing is selected", () => {
setup({ ...project(), references: [] });
expect(screen.getByText("Nothing selected")).toBeInTheDocument();
diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsx
index 9f7289c..5d785ec 100644
--- a/src/components/workspace/ReferencesView.tsx
+++ b/src/components/workspace/ReferencesView.tsx
@@ -1,4 +1,4 @@
-import { Add16, Audio22, ArrowDown12, ArrowUp12, ChevronLeft16, ChevronRight16, CursorClick32, Delete14, Delete16, FolderOpen16, GridView16, GridView16Filled, ImageAdd14, ImageAdd16, Images32, ListView16, ListView16Filled, OpenExternal16, Refresh16, Refresh20, Rename16, Search16, TextFile14, TextFile16, TextFile24 } from "../ui/icons";
+import { Add16, Audio22, ArrowDown12, ArrowUp12, ChevronLeft16, ChevronRight16, Copy16, CursorClick32, Delete14, Delete16, FolderOpen16, GridView16, GridView16Filled, ImageAdd14, ImageAdd16, Images32, ListView16, ListView16Filled, OpenExternal16, Refresh16, Refresh20, Rename16, Search16, TextFile14, TextFile16, TextFile24 } from "../ui/icons";
import { invoke } from "@tauri-apps/api/core";
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type KeyboardEvent, type MouseEvent } from "react";
import { isReferenceDescribed, projectItemPath, referenceImages, type ProjectConfig, type ProjectReference, type ProjectReferenceImage } from "../../lib/project";
@@ -86,8 +86,8 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,
}) {
const [selectedId, setSelectedId] = useState<string | undefined>(config.references[0]?.id);
/* Ctrl/Shift multi-select. `selectedId` stays the one reference the
- inspector edits (the last one clicked); `selectedIds` is what Delete acts
- on. A plain click makes them the same single reference again. */
+ inspector edits (the last one clicked); `selectedIds` is what Delete and
+ Duplicate act on. A plain click makes them the same single reference again. */
const [selectedIds, setSelectedIds] = useState<ReadonlySet<string>>(() => new Set(config.references[0] ? [config.references[0].id] : []));
const anchorId = useRef<string | undefined>(selectedId);
const [imagePage, setImagePage] = useState(0);
@@ -244,6 +244,28 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,
else if (action === "generate") onGenerateBuiltinIcons();
}).catch((reason) => setIconError(String(reason)));
};
+ const duplicate = (ids: readonly string[]) => {
+ const current = configRef.current;
+ const sources = new Set(ids);
+ const names = new Set(current.references.map((reference) => reference.name));
+ const copies: ProjectReference[] = [];
+ const references = current.references.flatMap((reference) => {
+ if (!sources.has(reference.id)) return [reference];
+ const baseName = `${reference.name} copy`;
+ let name = baseName;
+ for (let suffix = 2; names.has(name); suffix++) name = `${baseName} ${suffix}`;
+ names.add(name);
+ // Keep the media files, but give each copy independently editable settings.
+ const copy = { ...structuredClone(reference), id: `ref-${crypto.randomUUID()}`, name, createdAt: new Date().toISOString() };
+ copies.push(copy);
+ return [reference, copy];
+ });
+ if (!copies.length) return;
+ onChange({ ...current, references });
+ selectOnly(copies[0].id);
+ setSelectedIds(new Set(copies.map((copy) => copy.id)));
+ focusItem(copies[0].id);
+ };
/** Delete references (the selection by default) and every place that points
* at them: scene bindings, start/end frames and the image scene. */
const remove = (ids: readonly string[] = selection.length ? selection : selected ? [selected.id] : []) => {
@@ -394,6 +416,7 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,
const file = referenceFile(folderPath, reference);
const many = selection.length > 1 && selection.includes(reference.id);
return [
+ { id: "duplicate", label: many ? `Duplicate ${selection.length} references` : "Duplicate", icon: <Copy16 />, onSelect: () => duplicate(many ? selection : [reference.id]) },
{ id: "rename", label: "Rename", icon: <Rename16 />, shortcut: "F2", disabled: many, onSelect: () => rename(reference.id) },
{ id: "add-file", label: "Add file…", icon: <ImageAdd16 />, disabled: many || Boolean(reference.refmods?.length) || importingFiles, onSelect: () => { selectOnly(reference.id); void addFiles(reference.id); } },
{ id: "reveal", label: `Show in ${fileManagerName()}`, icon: <FolderOpen16 />, disabled: many || !file || !isTauri(), onSelect: () => { if (file) void revealInExplorer(file).catch((reason) => setImportError(String(reason))); } },