Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): correct three prompt affordances
joshistoast7ab925da8795
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsxindex 4ca2a6fb73..2af8dce0af 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx@@ -175,6 +175,7 @@ describe('the prompt templates panel', () => {catalog={createCatalog()}onApply={onApply}onCreate={vi.fn()}+ onDetach={vi.fn()}onEdit={vi.fn()}/>);@@ -202,6 +203,7 @@ describe('the prompt templates panel', () => {catalog={createCatalog()}onApply={onApply}onCreate={vi.fn()}+ onDetach={vi.fn()}onEdit={vi.fn()}/>);@@ -213,6 +215,40 @@ describe('the prompt templates panel', () => {expect(onApply).toHaveBeenCalledWith(null);});+ // Deleting the applied template has to stop it applying — otherwise it keeps+ // shaping every prompt with no way left to reach it. But that is not the same+ // intent as choosing to clear it, so the panel stays open: the user is in the+ // middle of managing the list.+ it('detaches rather than clears when the applied template is deleted', async () => {+ const onApply = vi.fn();+ const onDetach = vi.fn();++ await render(+ <PromptTemplatesPanel+ activeTemplate={userTemplate}+ catalog={createCatalog()}+ onApply={onApply}+ onCreate={vi.fn()}+ onDetach={onDetach}+ onEdit={vi.fn()}+ />+ );++ await act(async () => {+ await userEvent.click(host!.querySelector<HTMLButtonElement>('button[aria-label="Delete"]')!);+ });+ // The confirmation is portalled, so it is not under `host`.+ const dialog = document.querySelector('[role="alertdialog"]')!;+ const confirm = [...dialog.querySelectorAll('button')].find((button) => button.textContent === 'Delete')!;++ await act(async () => {+ await userEvent.click(confirm);+ });++ expect(onDetach).toHaveBeenCalled();+ expect(onApply).not.toHaveBeenCalled();+ });+// Built-ins are shipped by the backend and rejected by it for non-admins, so// offering the controls would only produce a 403.it('offers edit and delete on your own templates but not on built-ins', async () => {@@ -222,6 +258,7 @@ describe('the prompt templates panel', () => {catalog={createCatalog()}onApply={vi.fn()}onCreate={vi.fn()}+ onDetach={vi.fn()}onEdit={vi.fn()}/>);@@ -239,6 +276,7 @@ describe('the prompt templates panel', () => {catalog={createCatalog()}onApply={vi.fn()}onCreate={vi.fn()}+ onDetach={vi.fn()}onEdit={vi.fn()}/>);diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesButton.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesButton.tsxindex d9e3ea930b..797416acb8 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesButton.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesButton.tsx@@ -65,6 +65,9 @@ export const PromptTemplatesButton = ({[onApply]);+ /** Deleting the applied template stops it applying, but the panel stays open. */+ const detachTemplate = useCallback(() => onApply(null), [onApply]);+const startCreate = useCallback(() => setEditorTarget({ record: null }), []);const startEdit = useCallback((record: PromptTemplateRecord) => setEditorTarget({ record }), []);const closeEditor = useCallback(() => setEditorTarget(null), []);@@ -142,6 +145,7 @@ export const PromptTemplatesButton = ({activeTemplate={activeTemplate}catalog={catalog}onApply={applyAndClose}+ onDetach={detachTemplate}onCreate={startCreate}onEdit={startEdit}/>diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsxindex bbe7c2688f..481729de34 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx@@ -24,6 +24,11 @@ interface PromptTemplatesPanelProps {catalog: PromptTemplateCatalog;activeTemplate: PromptTemplateSnapshot | null;onApply: (template: PromptTemplateSnapshot | null) => void;+ /**+ * Stop applying the active template without dismissing the panel — for when it+ * has just been deleted, which is not the same intent as choosing to clear it.+ */+ onDetach: () => void;onEdit: (template: PromptTemplateRecord) => void;onCreate: () => void;}@@ -39,6 +44,7 @@ export const PromptTemplatesPanel = ({activeTemplate,catalog,onApply,+ onDetach,onCreate,onEdit,}: PromptTemplatesPanelProps) => {@@ -80,9 +86,11 @@ export const PromptTemplatesPanel = ({await catalog.remove(pendingDelete.id);// Deleting the template that is applied would otherwise leave it silently- // shaping every prompt with no way to reach it.+ // shaping every prompt with no way to reach it. Detached rather than+ // cleared: the user is in the middle of managing the list, and closing the+ // panel out from under them is not what they asked for.if (activeTemplate?.id === pendingDelete.id) {- onApply(null);+ onDetach();}} catch (caught) {notifications.reportError({@@ -91,7 +99,7 @@ export const PromptTemplatesPanel = ({namespace: 'generation',});}- }, [activeTemplate, catalog, notifications, onApply, pendingDelete, t]);+ }, [activeTemplate, catalog, notifications, onDetach, pendingDelete, t]);return (<Stack gap="2">diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTriggerPicker.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTriggerPicker.browser.test.tsxindex 15742852e7..37843cd72b 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTriggerPicker.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTriggerPicker.browser.test.tsx@@ -360,6 +360,30 @@ describe('the caret autocomplete', () => {expect(listbox()).toBeNull();});+ // Previously only a click could reopen the list over a reference already in+ // the prompt; arrowing back into one left it shut until another character was+ // typed, which reads as the feature having given up.+ it('reopens when the caret arrows back into a reference', async () => {+ await type('a photo of __co');+ await press('{Escape}');++ expect(listbox()).toBeNull();++ await press('{ArrowLeft}');++ expect(optionLabels()).toEqual(['colors']);+ });++ it('closes when the caret arrows out of one', async () => {+ await type('a photo of __co');++ expect(listbox()).not.toBeNull();++ await press('{Home}');++ expect(listbox()).toBeNull();+ });+it('closes on Escape and leaves the prompt exactly as typed', async () => {await type('a photo of __');await press('{Escape}');diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsxindex 2e4f904edd..84167501b7 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx@@ -28,6 +28,11 @@ import {} from '@features/generation/ui/promptFields/promptTriggerOptions';import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';+/** Move the caret whether or not the list is open. */+const CARET_KEYS = ['ArrowLeft', 'ArrowRight', 'Home', 'End'];+/** Move the caret only when the list is not open to take them for its own. */+const LIST_KEYS = ['ArrowUp', 'ArrowDown'];+interface AutocompleteState {caretRect: CaretRect;query: PromptTriggerQuery;@@ -54,6 +59,7 @@ export interface PromptTriggerAutocompleteApi {role: 'combobox';onCompositionEnd: (event: CompositionEvent<HTMLTextAreaElement>) => void;onCompositionStart: () => void;+ onKeyUp: (event: KeyboardEvent<HTMLTextAreaElement>) => void;};element: ReactNode;isOpen: boolean;@@ -171,10 +177,9 @@ export const usePromptTriggerAutocomplete = ({return;}- // A caret jump leaves the query behind, so the list goes with it — but the- // key still belongs to the textarea.- if (['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) {- setState(null);+ // Caret movement belongs to the textarea. Where it lands is read on the+ // way back up, once the browser has actually moved it.+ if (CARET_KEYS.includes(event.key)) {return;}@@ -206,6 +211,22 @@ export const usePromptTriggerAutocomplete = ({[activeIndex, isOpen, matches, selectOption]);+ // Read on the way up, not the way down: during keydown the caret has not moved+ // yet. This is also what lets the list *open* by arrowing back into a `__col`+ // that is already sitting in the prompt, which before only a click could do.+ //+ // The vertical arrows are excluded while the list is open, because there they+ // drove the highlight and the caret never moved — re-reading would reset the+ // highlight to the top on every press.+ const handleKeyUp = useCallback(+ (event: KeyboardEvent<HTMLTextAreaElement>) => {+ if (CARET_KEYS.includes(event.key) || (!isOpen && LIST_KEYS.includes(event.key))) {+ refresh(event.currentTarget);+ }+ },+ [isOpen, refresh]+ );+const handleCompositionStart = useCallback(() => {isComposingRef.current = true;setState(null);@@ -234,6 +255,7 @@ export const usePromptTriggerAutocomplete = ({// The loss is real and there is no way to state it here.onCompositionEnd: handleCompositionEnd,onCompositionStart: handleCompositionStart,+ onKeyUp: handleKeyUp,role: 'combobox',},element:diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsxindex b1067b2bb2..5a8a47b6ce 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx@@ -390,6 +390,9 @@ const SingleImageMenuItems = ({onClick={handleUseAsReferenceImage}/><ContextMenuItem+ // Same signal "Use Prompt" reads, rather than staying enabled and+ // raising a toast to say the image had no prompt after all.+ disabled={isLoadingRecallCapabilities || !recallCapabilities.prompts}icon={TypeIcon}label="Use as Prompt Template"value="use-as-prompt-template"