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.

refactor(webv2): move prompt editing toggles to user preferences

joshistoast4b31e89e091d
diff --git a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
index ef755d196b..b08f53b6ee 100644
--- a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
+++ b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
@@ -32,12 +32,20 @@ const GenerateCanvasCompositingSection = lazy(() =>
* Workbench, Models, and Gallery state. No second adapter is expected.
*/
export const GenerationUiAdapterProvider = ({ children }: { children: ReactNode }) => {
- const project = useActiveProjectSelector((activeProject) => ({
+ const projectState = useActiveProjectSelector((activeProject) => ({
activeProjectId: activeProject.id,
generateValues: getProjectWidgetValues(activeProject, 'generate'),
invocationSourceId: activeProject.invocation.sourceId,
- showPromptSyntaxHighlighting: activeProject.settings.showPromptSyntaxHighlighting,
}));
+ // Syntax highlighting is a per-user preference, not a property of the
+ // project, so it is joined here rather than read off the document.
+ const showPromptSyntaxHighlighting = useWorkbenchPreferenceSelector(
+ (preferences) => preferences.showPromptSyntaxHighlighting
+ );
+ const project = useMemo<GenerationUiAdapter['project']>(
+ () => ({ ...projectState, showPromptSyntaxHighlighting }),
+ [projectState, showPromptSyntaxHighlighting]
+ );
const promptHistoryItems = useActiveProjectSelector((activeProject) => activeProject.promptHistory);
const selectedGalleryImage = useActiveProjectSelector((activeProject) =>
getGenerationSelectedGalleryImage(getProjectWidgetValues(activeProject, 'gallery'))
diff --git a/invokeai/frontend/webv2/src/app/UpscaleUiAdapter.tsx b/invokeai/frontend/webv2/src/app/UpscaleUiAdapter.tsx
index 072dc1d163..54b048b995 100644
--- a/invokeai/frontend/webv2/src/app/UpscaleUiAdapter.tsx
+++ b/invokeai/frontend/webv2/src/app/UpscaleUiAdapter.tsx
@@ -5,6 +5,7 @@ import { invalidateGallery } from '@features/gallery/queries';
import { areProjectPromptDraftsEqual, getPromptDraftFromValues } from '@features/generation/settings';
import { UpscaleUiProvider } from '@features/upscale';
import { useQueryClient } from '@tanstack/react-query';
+import { useWorkbenchPreferenceSelector } from '@workbench/settings/store';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { useMemo } from 'react';
@@ -22,14 +23,17 @@ export const UpscaleUiAdapterProvider = ({ children }: { children: ReactNode })
projectId: activeProject.id,
promptDraft: getPromptDraftFromValues(getProjectWidgetValues(activeProject, 'generate')),
rawValues: instance?.state.values ?? {},
- showPromptSyntaxHighlighting: activeProject.settings.showPromptSyntaxHighlighting,
};
},
(left, right) =>
left.projectId === right.projectId &&
areProjectPromptDraftsEqual(left.promptDraft, right.promptDraft) &&
- left.rawValues === right.rawValues &&
- left.showPromptSyntaxHighlighting === right.showPromptSyntaxHighlighting
+ left.rawValues === right.rawValues
+ );
+ // Syntax highlighting is a per-user preference, not a property of the
+ // project, so it is joined here rather than read off the document.
+ const showPromptSyntaxHighlighting = useWorkbenchPreferenceSelector(
+ (preferences) => preferences.showPromptSyntaxHighlighting
);
const commands = useWorkbenchCommands();
const queryClient = useQueryClient();
@@ -40,9 +44,10 @@ export const UpscaleUiAdapterProvider = ({ children }: { children: ReactNode })
patchValues: (values, origin) => commands.widgets.patchValues('upscale', values, project.projectId, origin),
reportError: (message) =>
commands.notifications.reportError({ area: 'upscale', message, namespace: 'generation' }),
+ showPromptSyntaxHighlighting,
touchGalleryImages: () => void invalidateGallery(queryClient),
}),
- [commands, project, queryClient]
+ [commands, project, queryClient, showPromptSyntaxHighlighting]
);
return <UpscaleUiProvider adapter={adapter}>{children}</UpscaleUiProvider>;
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
index 56dcda36b0..1c9844acb7 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
@@ -22,6 +22,7 @@ import { submitActiveInvocation } from '@workbench/activeInvocationSubmission';
import { createLayoutPresetActivator, loadLayoutPresetWidgets } from '@workbench/layoutPresetActivation';
import { builtInLayoutPresetDescriptors, getLayoutPreset } from '@workbench/layoutPresets';
import { toggleCommandPalette } from '@workbench/palette/paletteStore';
+import { getWorkbenchPreferences } from '@workbench/settings/store';
import { openProjectSwitcher } from '@workbench/shell/topbar/projectSwitcherStore';
import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';
import { getWidgetsForRegion } from '@workbench/widgetRegistry';
@@ -307,20 +308,12 @@ export const useRegisterFirstPartyCommands = () => {
title: 'Next prompt history item',
}),
commandApi.register({
- handler: () =>
- adjustFocusedPromptAttention(
- 'increment',
- queries.getSnapshot().activeProject.settings.preferNumericAttentionStyle
- ),
+ handler: () => adjustFocusedPromptAttention('increment', getWorkbenchPreferences().preferNumericAttentionStyle),
id: 'app.promptWeightUp',
title: 'Increase prompt weight',
}),
commandApi.register({
- handler: () =>
- adjustFocusedPromptAttention(
- 'decrement',
- queries.getSnapshot().activeProject.settings.preferNumericAttentionStyle
- ),
+ handler: () => adjustFocusedPromptAttention('decrement', getWorkbenchPreferences().preferNumericAttentionStyle),
id: 'app.promptWeightDown',
title: 'Decrease prompt weight',
}),
diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
index 681f90775f..98dd6a6d2a 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
@@ -377,8 +377,14 @@ const ThemeCard = ({
};
const BehaviorSection = () => {
- const { autoSwitchInvocationRoute, confirmImageDeletion, enableInformationalPopovers, enableModelDescriptions } =
- useWorkbenchPreferences();
+ const {
+ autoSwitchInvocationRoute,
+ confirmImageDeletion,
+ enableInformationalPopovers,
+ enableModelDescriptions,
+ preferNumericAttentionStyle,
+ showPromptSyntaxHighlighting,
+ } = useWorkbenchPreferences();
const updateAutoSwitchInvocationRoute = useCallback((checked: boolean) => {
updatePreferences({ autoSwitchInvocationRoute: checked });
}, []);
@@ -391,9 +397,18 @@ const BehaviorSection = () => {
const updateEnableModelDescriptions = useCallback((checked: boolean) => {
updatePreferences({ enableModelDescriptions: checked });
}, []);
+ const updatePreferNumericAttentionStyle = useCallback((checked: boolean) => {
+ updatePreferences({ preferNumericAttentionStyle: checked });
+ }, []);
+ const updateShowPromptSyntaxHighlighting = useCallback((checked: boolean) => {
+ updatePreferences({ showPromptSyntaxHighlighting: checked });
+ }, []);
return (
- <SettingsSection description="Safety checks and user-assistance behavior." title="Behavior">
+ <SettingsSection
+ description="Safety checks, prompt editing, and user-assistance behavior."
+ title="Behavior"
+ >
<SettingToggle
checked={autoSwitchInvocationRoute}
description="Switch the Invoke source and destination to match the surface you are editing. Locked sources and destinations are never changed."
@@ -418,6 +433,18 @@ const BehaviorSection = () => {
label="Enable model descriptions in dropdowns"
onChange={updateEnableModelDescriptions}
/>
+ <SettingToggle
+ checked={preferNumericAttentionStyle}
+ description="Prefer numeric prompt attention syntax when controls insert attention weights."
+ label="Prefer numeric attention style"
+ onChange={updatePreferNumericAttentionStyle}
+ />
+ <SettingToggle
+ checked={showPromptSyntaxHighlighting}
+ description="Experimental. Color prompt syntax in prompt fields without changing the prompt text or validation behavior."
+ label="Highlight prompt syntax (experimental)"
+ onChange={updateShowPromptSyntaxHighlighting}
+ />
</SettingsSection>
);
};
@@ -453,24 +480,6 @@ const ProjectSection = () => {
},
[updateProjectSettings]
);
- const updateShowProgressImagesInViewer = useCallback(
- (checked: boolean) => {
- updateProjectSettings({ showProgressImagesInViewer: checked });
- },
- [updateProjectSettings]
- );
- const updatePreferNumericAttentionStyle = useCallback(
- (checked: boolean) => {
- updateProjectSettings({ preferNumericAttentionStyle: checked });
- },
- [updateProjectSettings]
- );
- const updateShowPromptSyntaxHighlighting = useCallback(
- (checked: boolean) => {
- updateProjectSettings({ showPromptSyntaxHighlighting: checked });
- },
- [updateProjectSettings]
- );
if (!activeProject || !commands) {
return null;
@@ -502,24 +511,6 @@ const ProjectSection = () => {
label="Antialias progress images"
onChange={updateAntialiasProgressImages}
/>
- <SettingToggle
- checked={settings.showProgressImagesInViewer}
- description="Show progress images in the viewer when an image is still generating."
- label="Show progress images in viewer"
- onChange={updateShowProgressImagesInViewer}
- />
- <SettingToggle
- checked={settings.preferNumericAttentionStyle}
- description="Prefer numeric prompt attention syntax when controls insert attention weights."
- label="Prefer numeric attention style"
- onChange={updatePreferNumericAttentionStyle}
- />
- <SettingToggle
- checked={settings.showPromptSyntaxHighlighting}
- description="Experimental. Color prompt syntax in prompt fields without changing the prompt text or validation behavior."
- label="Highlight prompt syntax (experimental)"
- onChange={updateShowPromptSyntaxHighlighting}
- />
</SettingsSection>
);
};
diff --git a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts b/invokeai/frontend/webv2/src/workbench/settings/contracts.ts
index af37329410..a41f9ba2a1 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts
+++ b/invokeai/frontend/webv2/src/workbench/settings/contracts.ts
@@ -7,13 +7,22 @@ export type { ProjectSortId, ProjectsViewId } from '@workbench/launchpad/project
export type { WorkbenchLanguage } from '@platform/i18n/languages';
+/**
+ * Settings that belong to the *project* and therefore travel inside its `.invk`
+ * export. Anything describing how a person likes to work — as opposed to how
+ * this document generates — belongs in {@link WorkbenchPreferences} instead, so
+ * that opening someone else's project cannot rewrite your editor.
+ */
export interface ProjectSettings {
useCpuNoise: boolean;
showProgressDetails: boolean;
antialiasProgressImages: boolean;
+ /**
+ * Not surfaced in the Settings dialog: the Preview widget's header owns this
+ * as a live toggle, and following a generation flips it implicitly. It is
+ * persisted per project because that is the lifetime the toggle expects.
+ */
showProgressImagesInViewer: boolean;
- preferNumericAttentionStyle: boolean;
- showPromptSyntaxHighlighting: boolean;
}
/**
@@ -44,6 +53,10 @@ export interface WorkbenchPreferences {
language: WorkbenchLanguage;
enableInformationalPopovers: boolean;
enableModelDescriptions: boolean;
+ /** Write numeric attention weights (`(word)1.1`) when the attention hotkeys insert them. */
+ preferNumericAttentionStyle: boolean;
+ /** Experimental. Color prompt syntax in prompt fields; changes rendering only. */
+ showPromptSyntaxHighlighting: boolean;
developerLogEnabled: boolean;
developerLogLevel: DeveloperLogLevel;
developerLogNamespaces: DeveloperLogNamespace[];
diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.test.ts b/invokeai/frontend/webv2/src/workbench/settings/store.test.ts
index 90fee9da74..9737e5e8a2 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/store.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/settings/store.test.ts
@@ -2,6 +2,7 @@ import type * as accountLifecycleModule from '@platform/state/accountLifecycle';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import type { ProjectSettings } from './contracts';
import type * as storeModule from './store';
/**
@@ -331,15 +332,45 @@ describe('clearWorkbenchSettings', () => {
});
describe('normalizeProjectSettings', () => {
- it('defaults prompt syntax highlighting off for older project payloads', () => {
- expect(store.normalizeProjectSettings({}).showPromptSyntaxHighlighting).toBe(false);
- expect(store.normalizeProjectSettings({ showPromptSyntaxHighlighting: true }).showPromptSyntaxHighlighting).toBe(
- true
- );
- expect(store.normalizeProjectSettings({ showPromptSyntaxHighlighting: false }).showPromptSyntaxHighlighting).toBe(
+ it('defaults progress-image behavior for older project payloads', () => {
+ expect(store.normalizeProjectSettings({}).showProgressImagesInViewer).toBe(true);
+ expect(store.normalizeProjectSettings({ showProgressImagesInViewer: false }).showProgressImagesInViewer).toBe(
false
);
});
+
+ /**
+ * Prompt highlighting and attention style used to be project settings. They
+ * are per-user preferences now, and a document written by an older build
+ * still carries them — normalizing must not let them back in, or importing
+ * someone else's project would rewrite the reader's editor.
+ */
+ it('drops prompt preferences that older documents still carry in project settings', () => {
+ const normalized = store.normalizeProjectSettings({
+ preferNumericAttentionStyle: true,
+ showPromptSyntaxHighlighting: true,
+ } as Partial<ProjectSettings>);
+
+ expect(normalized).not.toHaveProperty('showPromptSyntaxHighlighting');
+ expect(normalized).not.toHaveProperty('preferNumericAttentionStyle');
+ });
+});
+
+describe('normalizeWorkbenchPreferences prompt editing', () => {
+ it('defaults prompt syntax highlighting and numeric attention style off', () => {
+ expect(store.normalizeWorkbenchPreferences({}).showPromptSyntaxHighlighting).toBe(false);
+ expect(store.normalizeWorkbenchPreferences({}).preferNumericAttentionStyle).toBe(false);
+ });
+
+ it('round-trips both prompt preferences', () => {
+ const normalized = store.normalizeWorkbenchPreferences({
+ preferNumericAttentionStyle: true,
+ showPromptSyntaxHighlighting: true,
+ });
+
+ expect(normalized.showPromptSyntaxHighlighting).toBe(true);
+ expect(normalized.preferNumericAttentionStyle).toBe(true);
+ });
});
describe('normalizeWorkbenchPreferences diagnostics', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.ts b/invokeai/frontend/webv2/src/workbench/settings/store.ts
index 515323b0a5..1032b996ca 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/store.ts
+++ b/invokeai/frontend/webv2/src/workbench/settings/store.ts
@@ -47,8 +47,6 @@ export const DEVELOPER_LOG_NAMESPACES: DeveloperLogNamespace[] = [
export const DEFAULT_PROJECT_SETTINGS: ProjectSettings = {
antialiasProgressImages: false,
- preferNumericAttentionStyle: false,
- showPromptSyntaxHighlighting: false,
showProgressDetails: false,
showProgressImagesInViewer: true,
useCpuNoise: true,
@@ -70,8 +68,10 @@ export const DEFAULT_PREFERENCES: WorkbenchPreferences = {
launchpadPinnedProjectIds: [],
launchpadProjectsSort: 'edited',
launchpadProjectsView: 'grid',
+ preferNumericAttentionStyle: false,
queueJobsScope: 'all',
reduceMotion: false,
+ showPromptSyntaxHighlighting: false,
showFocusRegionHighlight: true,
themeId: DEFAULT_THEME_ID,
workflowEdgeStyle: 'curved',
@@ -231,14 +231,6 @@ export const normalizeProjectSettings = (settings?: Partial<ProjectSettings>): P
typeof settings?.antialiasProgressImages === 'boolean'
? settings.antialiasProgressImages
: DEFAULT_PROJECT_SETTINGS.antialiasProgressImages,
- preferNumericAttentionStyle:
- typeof settings?.preferNumericAttentionStyle === 'boolean'
- ? settings.preferNumericAttentionStyle
- : DEFAULT_PROJECT_SETTINGS.preferNumericAttentionStyle,
- showPromptSyntaxHighlighting:
- typeof settings?.showPromptSyntaxHighlighting === 'boolean'
- ? settings.showPromptSyntaxHighlighting
- : DEFAULT_PROJECT_SETTINGS.showPromptSyntaxHighlighting,
showProgressDetails:
typeof settings?.showProgressDetails === 'boolean'
? settings.showProgressDetails
@@ -300,6 +292,10 @@ export const normalizeWorkbenchPreferences = (preferences?: WorkbenchPreferences
launchpadProjectsView: isProjectsViewId(preferences?.launchpadProjectsView)
? preferences.launchpadProjectsView
: DEFAULT_PREFERENCES.launchpadProjectsView,
+ preferNumericAttentionStyle:
+ typeof preferences?.preferNumericAttentionStyle === 'boolean'
+ ? preferences.preferNumericAttentionStyle
+ : DEFAULT_PREFERENCES.preferNumericAttentionStyle,
queueJobsScope:
preferences?.queueJobsScope === 'all-projects'
? 'all'
@@ -312,6 +308,10 @@ export const normalizeWorkbenchPreferences = (preferences?: WorkbenchPreferences
typeof preferences?.showFocusRegionHighlight === 'boolean'
? preferences.showFocusRegionHighlight
: DEFAULT_PREFERENCES.showFocusRegionHighlight,
+ showPromptSyntaxHighlighting:
+ typeof preferences?.showPromptSyntaxHighlighting === 'boolean'
+ ? preferences.showPromptSyntaxHighlighting
+ : DEFAULT_PREFERENCES.showPromptSyntaxHighlighting,
themeId: isWorkbenchThemeId(preferences?.themeId) ? preferences.themeId : DEFAULT_PREFERENCES.themeId,
workflowEdgeStyle:
preferences?.workflowEdgeStyle === 'square' || preferences?.workflowEdgeStyle === 'straight'
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
index d15f6a7890..88fb24ee2f 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
@@ -25,8 +25,9 @@ import {
} from '@platform/state/accountLifecycle';
import { Button, ColorPicker, DropZone, Field, Select, Slider } from '@platform/ui';
import { useQueryClient } from '@tanstack/react-query';
+import { useWorkbenchPreferenceSelector } from '@workbench/settings/store';
import { useCanvasProjectMutationDispatch } from '@workbench/useCanvasProjectMutationDispatch';
-import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
+import { useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { ImageIcon, PlusIcon, XIcon } from 'lucide-react';
import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -99,7 +100,9 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
const queryClient = useQueryClient();
const models = useModelsSelector((snapshot) => snapshot.models);
const base = useSelectedModelBase();
- const showSyntaxHighlighting = useActiveProjectSelector((project) => project.settings.showPromptSyntaxHighlighting);
+ const showSyntaxHighlighting = useWorkbenchPreferenceSelector(
+ (preferences) => preferences.showPromptSyntaxHighlighting
+ );
const fillBeforeRef = useRef<CanvasMaskFillContract | null>(null);
const [positivePrompt, setPositivePrompt] = useState(layer.positivePrompt ?? '');
const [negativePrompt, setNegativePrompt] = useState(layer.negativePrompt ?? '');
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 35cb75b299..d323951acf 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -2477,16 +2477,14 @@ describe('workbench account and project settings', () => {
let state = createInitialWorkbenchState();
state = workbenchReducer(state, {
- settings: { antialiasProgressImages: true, preferNumericAttentionStyle: true, useCpuNoise: false },
+ settings: { antialiasProgressImages: true, useCpuNoise: false },
type: 'setActiveProjectSettings',
});
expect(getActiveProject(state).settings).toEqual({
antialiasProgressImages: true,
- preferNumericAttentionStyle: true,
showProgressDetails: false,
showProgressImagesInViewer: true,
- showPromptSyntaxHighlighting: false,
useCpuNoise: false,
});
});