AI media harness for planning, generating, and editing locally
TypeScript
Highlight selected reference chips
Bitti43f968d87ab1
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex 63bdfa7..2a6d5d6 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -25,6 +25,7 @@ This alpha update adds DMAD LoRA support, resumable model downloads, and improve## Fixes and improvements+- Reference chips now highlight when included in a prompt's text selection.- The Video scene list scrollbar no longer overlaps the Generate and Cancel buttons.- Timeline media thumbnails stay inside their preview area, keeping filenames clear in grid and list layouts.- Portable builds show available updates and open GitHub releases for manual updating instead of running an installer.diff --git a/src/components/workspace/PromptTextField.test.tsx b/src/components/workspace/PromptTextField.test.tsxindex 016b6e3..04ef421 100644--- a/src/components/workspace/PromptTextField.test.tsx+++ b/src/components/workspace/PromptTextField.test.tsx@@ -40,12 +40,53 @@ const selectRange = (start: Node, startOffset: number, end: Node, endOffset: numrange.setEnd(end, endOffset);document.getSelection()!.removeAllRanges();document.getSelection()!.addRange(range);+ fireEvent(document, new Event("selectionchange"));};const clipboard = () => {const data = new Map<string, string>();return { setData: (type: string, value: string) => data.set(type, value), getData: (type: string) => data.get(type) ?? "" };};+it("highlights only the selected chip occurrences, including missing references, and clears on collapse", () => {+ const initial = "Before @[ref:hero] between @[ref:hero] after @[ref:missing]";+ const { field, value } = setup(initial);+ const [first, second, missing] = field.querySelectorAll(".prompt-chip");+ selectRange(field, 1, field, 2);+ expect(first).toHaveClass("prompt-chip--selected");+ expect(second).not.toHaveClass("prompt-chip--selected");+ expect(missing).not.toHaveClass("prompt-chip--selected");+ selectRange(field, 3, field, 6);+ expect(first).not.toHaveClass("prompt-chip--selected");+ expect(second).toHaveClass("prompt-chip--selected");+ expect(missing).toHaveClass("prompt-chip--selected", "prompt-chip--missing");+ expect(value()).toBe(initial);+ expect(field.querySelectorAll(".prompt-chip")[0]).toBe(first);+ caretAt(field, 3);+ expect(field.querySelector(".prompt-chip--selected")).toBeNull();+});++it("highlights partial chip selections in either direction and clears when selection moves to another field", () => {+ render(<>+ <PromptTextField aria-label="First" value="@[ref:hero]" onChange={vi.fn()} references={references} />+ <PromptTextField aria-label="Second" value="@[ref:castle]" onChange={vi.fn()} references={references} />+ </>);+ const first = screen.getByRole("textbox", { name: "First" });+ const second = screen.getByRole("textbox", { name: "Second" });+ const hero = first.querySelector(".prompt-chip")!;+ const castle = second.querySelector(".prompt-chip")!;+ selectRange(hero.firstChild!, 1, hero.firstChild!, 3);+ expect(hero).toHaveClass("prompt-chip--selected");+ document.getSelection()!.setBaseAndExtent(hero.firstChild!, 3, hero.firstChild!, 1);+ fireEvent(document, new Event("selectionchange"));+ expect(hero).toHaveClass("prompt-chip--selected");+ selectRange(second, 0, second, 1);+ expect(hero).not.toHaveClass("prompt-chip--selected");+ expect(castle).toHaveClass("prompt-chip--selected");+ document.getSelection()!.removeAllRanges();+ fireEvent(document, new Event("selectionchange"));+ expect(castle).not.toHaveClass("prompt-chip--selected");+});+it.each(["", "\n"])("copies multiline prompts with chip IDs into another field (ending: %j)", (ending) => {const initial = `Meet @[ref:hero]\n@[ref:castle] with @[ref:hero] and @[ref:missing]${ending}`;const onInsert = vi.fn();diff --git a/src/components/workspace/PromptTextField.tsx b/src/components/workspace/PromptTextField.tsxindex 57a7529..85a54a8 100644--- a/src/components/workspace/PromptTextField.tsx+++ b/src/components/workspace/PromptTextField.tsx@@ -116,6 +116,7 @@ export function PromptTextField({ value, onChange, references, format = REFERENCselection.current = { start: pendingCaret.current, end: pendingCaret.current };pendingCaret.current = null;}+ highlightSelectedChips(root);// eslint-disable-next-line react-hooks/exhaustive-deps}, [value, chipsKey]);@@ -126,6 +127,7 @@ export function PromptTextField({ value, onChange, references, format = REFERENCconst root = field.current;const range = root && caretRange(root, format);if (range) selection.current = range;+ if (root) highlightSelectedChips(root);};document.addEventListener("selectionchange", remember);return () => document.removeEventListener("selectionchange", remember);@@ -350,6 +352,16 @@ function ReferencePicker({ picking, references, format, label, onChoose, onRemov/* --- The editable surface ------------------------------------------------ */+/** Noneditable chips do not receive the browser's text-selection paint.+ * Update their appearance directly so selection changes never rebuild the DOM. */+function highlightSelectedChips(root: HTMLElement) {+ const selection = document.getSelection();+ const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index)).filter((range) => !range.collapsed) : [];+ root.querySelectorAll<HTMLElement>(`[${CHIP}]`).forEach((chip) => {+ chip.classList.toggle("prompt-chip--selected", ranges.some((range) => range.intersectsNode(chip)));+ });+}+function chipElement(key: string, chips: Chips, missingTooltip: string): HTMLElement {const reference = chips.byKey.get(key);const name = reference?.name ?? chips.missingLabel(key);@@ -459,6 +471,7 @@ function placeCaret(root: HTMLElement, offset: number, format: PromptTokenFormatconst selection = document.getSelection();selection?.removeAllRanges();selection?.addRange(range);+ highlightSelectedChips(root);}function wrap(node: Node): Node {diff --git a/src/styles/prompt-field.css b/src/styles/prompt-field.cssindex 86b7dad..bb6753d 100644--- a/src/styles/prompt-field.css+++ b/src/styles/prompt-field.css@@ -74,6 +74,14 @@.prompt-chip--missing:hover { background: var(--danger-soft-strong); }.prompt-field--disabled .prompt-chip { cursor: default; opacity: 0.6; }+/* Match the platform's selection colors, including in high-contrast mode. */+.prompt-chip.prompt-chip--selected {+ color: HighlightText;+ background: Highlight;+ border-color: Highlight;+ opacity: 1;+}+.prompt-reference-picker { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-2); }.prompt-reference-picker__current { margin: 0; padding: var(--space-1) var(--space-2); color: var(--text-secondary); font-size: var(--text-xs); }.prompt-reference-picker__list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow-y: auto; }