Skip to content

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.

fix(webv2): open the autocomplete when view mode has no template

joshistoast8c09a3f8db98
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/NegativePromptField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/NegativePromptField.tsx
index 1c5493b7e2..e90c7a5e83 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/NegativePromptField.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/NegativePromptField.tsx
@@ -86,8 +86,14 @@ export const NegativePromptField = ({
setTriggerPickerState({ anchorRect: { height: rect.height, width: rect.width, x: rect.x, y: rect.y } });
}, []);
+ // Same textarea, read-only, as on the positive side — swapping in a different
+ // component would reset the resizer's mounted height. The `&&` matters: view
+ // mode with no template leaves the prompt editable, so gating on the toggle
+ // alone would kill the autocomplete while the user is still typing.
+ const isViewingMerged = isTemplateViewMode && templateNegativePrompt !== null;
+
const autocomplete = usePromptTriggerAutocomplete({
- isDisabled: isTemplateViewMode,
+ isDisabled: isViewingMerged,
keys: NEGATIVE_PROMPT_TRIGGER_KEYS,
loras,
onChange: commitPromptChange,
@@ -187,9 +193,6 @@ export const NegativePromptField = ({
[triggerPickerState]
);
- // Same textarea, read-only, as on the positive side — swapping in a different
- // component would reset the resizer's mounted height.
- const isViewingMerged = isTemplateViewMode && templateNegativePrompt !== null;
const templateChunks = useMemo(
() => (isViewingMerged ? getPromptTemplateChunks(draftValue, templateNegativePrompt) : null),
[draftValue, isViewingMerged, templateNegativePrompt]
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
index 4267451f0c..e01fff30fa 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
@@ -108,8 +108,18 @@ export const PositivePromptField = ({
setTriggerPickerState({ anchorRect: { height: rect.height, width: rect.width, x: rect.x, y: rect.y } });
}, []);
+ // View mode keeps the same textarea rather than swapping in a preview
+ // component: `ResizableTextarea` reads its height once on mount, and the
+ // element is also what `focusPositivePrompt` and the attention hotkeys target,
+ // so unmounting it would reset the height and break both.
+ //
+ // Note the `&&`: view mode with no template applied leaves the prompt fully
+ // editable, so gating anything on the toggle alone silently disables it while
+ // the user is still typing.
+ const isViewingMerged = isTemplateViewMode && promptTemplate !== null;
+
const autocomplete = usePromptTriggerAutocomplete({
- isDisabled: isTemplateViewMode,
+ isDisabled: isViewingMerged,
keys: POSITIVE_PROMPT_TRIGGER_KEYS,
loras,
onChange: commitPromptChange,
@@ -243,11 +253,6 @@ export const PositivePromptField = ({
/** Clicking moves the caret, which may land in — or out of — a trigger. */
const handlePromptClick = useCallback(() => autocomplete.refresh(textareaRef.current), [autocomplete]);
- // View mode keeps the same textarea rather than swapping in a preview
- // component: `ResizableTextarea` reads its height once on mount, and the
- // element is also what `focusPositivePrompt` and the attention hotkeys target,
- // so unmounting it would reset the height and break both.
- const isViewingMerged = isTemplateViewMode && promptTemplate !== null;
const templateChunks = useMemo(
() => (isViewingMerged ? getPromptTemplateChunks(draftValue, promptTemplate.positivePrompt) : null),
[draftValue, isViewingMerged, promptTemplate]
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.tsx
index 8ca067cf29..f0c0d43171 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
@@ -40,7 +40,7 @@ let root: Root | null = null;
/** Tall on purpose: the old picker anchored to the whole box, which is the bug. */
const TEXTAREA_HEIGHT_PX = 320;
-const render = async () => {
+const render = async (isTemplateViewMode = false) => {
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
@@ -51,6 +51,7 @@ const render = async () => {
<ChakraProvider value={system}>
<PositivePromptField
heightPx={TEXTAREA_HEIGHT_PX}
+ isTemplateViewMode={isTemplateViewMode}
loras={[]}
projectId="project-1"
selectedModel={undefined}
@@ -228,4 +229,17 @@ describe('the caret autocomplete', () => {
expect(listbox()).toBeNull();
});
+
+ // Regression: the template view-mode toggle can be on with no template
+ // applied, which leaves the prompt fully editable. Gating on the toggle alone
+ // killed the autocomplete outright while the user was still typing.
+ it('still opens when view mode is on but no template is applied', async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ await render(true);
+ await type('a photo of __');
+
+ expect(textarea().readOnly).toBe(false);
+ expect(optionLabels()).toEqual(['colors', 'moods']);
+ });
});