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.

feat(workflows): switch between graph and form by keyboard (#10226)

rnshine53649442e5ef
diff --git a/docs/src/content/docs/Users Guide/08.Workflows/editor-reference.mdx b/docs/src/content/docs/Users Guide/08.Workflows/editor-reference.mdx
index 470af02cca..0cade0c161 100644
--- a/docs/src/content/docs/Users Guide/08.Workflows/editor-reference.mdx
+++ b/docs/src/content/docs/Users Guide/08.Workflows/editor-reference.mdx
@@ -110,7 +110,9 @@ The community has written many more nodes, from image effects to prompt tools. T
## Keyboard shortcuts
-These work while the workflow editor has focus. On macOS, use **Cmd** in place of **Ctrl**.
+With focus in the workflow graph editor or the left Workflow panel, press **Shift+Z** to move focus to the other view. To change the shortcut, find **Switch workflow view** in **Settings → Hotkeys**.
+
+The shortcuts below work while the workflow editor has focus. On macOS, use **Cmd** in place of **Ctrl**.
| Shortcut | Action |
|---|---|
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/WorkbenchNavigation.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/hotkeys/WorkbenchNavigation.browser.test.tsx
index 524d933d2a..562e8d52c6 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/WorkbenchNavigation.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/WorkbenchNavigation.browser.test.tsx
@@ -271,6 +271,128 @@ it('respects modal suspension and custom bindings', async () => {
await expectFocusedRegion('center');
});
+it('moves focus between the workflow graph and a collapsed workflow panel, preserving both views', async () => {
+ await act(() => {
+ runtime.store.commands.layout.applyPreset('automate');
+ runtime.store.commands.widgets.patchValues('workflow', { editTab: 'json', panelMode: 'edit' });
+ runtime.store.commands.layout.setRegionCollapsed('left', true);
+ });
+ const before = project();
+ expect(before.widgetRegions.left.isCollapsed).toBe(true);
+ await focusRegion('center');
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('left');
+ expect(project().widgetRegions.left).toEqual({ ...before.widgetRegions.left, isCollapsed: false });
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('center');
+ expect(project().widgetRegions.center).toEqual(before.widgetRegions.center);
+ expect(project().widgetInstances).toBe(before.widgetInstances);
+ expect(project().workflows).toBe(before.workflows);
+});
+
+it.each([
+ { graphInstanceId: 'workflow:center', leftInstanceId: 'workflow' },
+ { graphInstanceId: 'workflow:bottom', leftInstanceId: 'workflow:center' },
+])(
+ 'opens the Compose workflow graph while keeping the $leftInstanceId panel visible',
+ async ({ graphInstanceId, leftInstanceId }) => {
+ await act(() => {
+ runtime.store.commands.layout.applyPreset('compose');
+ if (leftInstanceId === 'workflow') {
+ runtime.store.commands.widgets.open({ region: 'left', widgetId: 'workflow' });
+ } else {
+ runtime.store.commands.widgets.toggle({ region: 'left', widgetId: leftInstanceId });
+ }
+ });
+ const before = project();
+ const left = before.widgetRegions.left;
+ expect(before.layout.presetId).toBe('compose');
+ expect(left.activeInstanceId).toBe(leftInstanceId);
+ expect(before.widgetRegions.center.instanceIds).not.toContain(graphInstanceId);
+ await focusRegion('left');
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('center');
+ expect(project().widgetRegions.left).toEqual(left);
+ expect(project().layout.panels.isLeftOpen).toBe(true);
+ expect(project().widgetRegions.center.activeInstanceId).toBe(graphInstanceId);
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('left');
+ expect(project().widgetRegions.left).toEqual(left);
+ expect(project().widgetRegions.center.activeInstanceId).toBe(graphInstanceId);
+ }
+);
+
+it('selects the existing Compose graph while preserving the shared left Workflow panel', async () => {
+ await act(() => runtime.store.commands.layout.applyPreset('compose'));
+ await press('4');
+ const graphInstanceId = project().widgetRegions.center.activeInstanceId;
+ expect(project().widgetInstances[graphInstanceId]?.typeId).toBe('workflow');
+
+ await act(() => {
+ runtime.store.commands.widgets.open({ region: 'left', widgetId: 'workflow' });
+ runtime.store.commands.widgets.select({ region: 'center', widgetId: 'preview' });
+ });
+ const before = project();
+ expect(before.widgetRegions.left.activeInstanceId).toBe(graphInstanceId);
+ expect(before.widgetRegions.center.activeInstanceId).toBe('preview');
+ expect(before.widgetRegions.center.instanceIds).toContain(graphInstanceId);
+ await focusRegion('left');
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('center');
+ expect(project().widgetRegions.left).toEqual(before.widgetRegions.left);
+ expect(project().layout.panels.isLeftOpen).toBe(true);
+ expect(project().widgetRegions.center).toEqual({
+ ...before.widgetRegions.center,
+ activeInstanceId: graphInstanceId,
+ });
+
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('left');
+ expect(project().widgetRegions.left).toEqual(before.widgetRegions.left);
+ expect(project().widgetRegions.center.activeInstanceId).toBe(graphInstanceId);
+});
+
+it('reopens a bottom workflow graph using the remapped shortcut only from workflow surfaces', async () => {
+ await act(() => {
+ runtime.store.commands.widgets.open({ region: 'bottom', widgetId: 'workflow' });
+ runtime.store.commands.widgets.open({ region: 'left', widgetId: 'workflow' });
+ runtime.store.commands.layout.setRegionCollapsed('bottom', true);
+ });
+ const before = project();
+ expect(before.widgetRegions.bottom.isCollapsed).toBe(true);
+
+ await focusRegion('right');
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('right');
+ expect(project()).toBe(before);
+
+ const workflowId = before.widgetRegions.left.activeInstanceId;
+ const textarea = host.querySelector<HTMLTextAreaElement>(`[aria-label="${workflowId} text"]`)!;
+ await act(() => textarea.focus());
+ await press('{Shift>}Z{/Shift}');
+ expect(textarea.value).toBe('Z');
+ expect(document.activeElement).toBe(textarea);
+ expect(project()).toBe(before);
+
+ await focusRegion('left');
+ await act(() => patchWorkbenchPreferences({ customHotkeys: { 'app.switchWorkflowView': ['shift+j'] } }));
+ await press('{Shift>}Z{/Shift}');
+ await expectFocusedRegion('left');
+ expect(project()).toBe(before);
+
+ await press('{Shift>}J{/Shift}');
+ await expectFocusedRegion('bottom');
+ expect(project().widgetRegions.bottom).toEqual({ ...before.widgetRegions.bottom, isCollapsed: false });
+ expect(project().widgetRegions.center).toEqual(before.widgetRegions.center);
+ await press('{Shift>}J{/Shift}');
+ await expectFocusedRegion('left');
+});
+
it('does not cycle a floating window and can move from it to a docked region', async () => {
const window = host.querySelector<HTMLElement>('[data-floating-window]')!;
await act(() => window.focus());
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
index 91bdb9c51e..f73a5484a5 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts
@@ -161,6 +161,10 @@ export const firstPartyHotkeyCatalog: HotkeyDefinition[] = [
hotkey('app', 'selectCanvasTab', ['2'], { title: 'Open Canvas' }),
hotkey('app', 'selectUpscalingTab', ['3'], { title: 'Open Upscale' }),
hotkey('app', 'selectWorkflowsTab', ['4'], { title: 'Open Workflow editor' }),
+ hotkey('app', 'switchWorkflowView', ['shift+z'], {
+ scope: categoryScopes.workflows,
+ title: 'Switch workflow view',
+ }),
hotkey('app', 'selectModelsTab', ['5'], { title: 'Open Model Manager' }),
hotkey('app', 'selectQueueTab', ['6'], { title: 'Open Queue' }),
hotkey('app', 'openWidgets', [], { title: 'Show widgets' }),
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
index fdf9987022..4337d7fd1f 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
@@ -29,7 +29,12 @@ import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';
import { getWorkbenchPreferences } from '@workbench/settings/store';
import { openProjectSwitcher } from '@workbench/shell/topbar/projectSwitcherStore';
import { openWidgetsDialog } from '@workbench/shell/widgetsDialogStore';
-import { cycleRegionWidget, openWidgetPlacement, toggleCenterPreview } from '@workbench/widgetPlacementCommands';
+import {
+ cycleRegionWidget,
+ getOpenableWidgetPlacement,
+ openWidgetPlacement,
+ toggleCenterPreview,
+} from '@workbench/widgetPlacementCommands';
import { getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';
import { getWidgetsForRegion } from '@workbench/widgetRegistry';
import { getProjectWidgetValues } from '@workbench/widgetState';
@@ -80,6 +85,7 @@ export const FIRST_PARTY_APP_COMMAND_IDS = [
'app.selectCanvasTab',
'app.selectUpscalingTab',
'app.selectWorkflowsTab',
+ 'app.switchWorkflowView',
'app.selectModelsTab',
'app.selectQueueTab',
'app.openWidgets',
@@ -289,6 +295,99 @@ export const useRegisterFirstPartyCommands = () => {
}
};
+ const switchWorkflowView = () => {
+ const project = queries.getSnapshot().activeProject;
+ const target = getFocusTarget();
+ const graphRegions = ['center', 'bottom'] as const;
+ const isWorkflow = (instanceId: string) => project.widgetInstances[instanceId]?.typeId === 'workflow';
+ const hasWorkflow = (region: 'center' | 'bottom' | 'left') =>
+ project.widgetRegions[region].instanceIds.some(isWorkflow);
+ const visibleWorkflow = (region: 'center' | 'bottom' | 'left') => {
+ const { activeInstanceId, instanceIds, isCollapsed } = project.widgetRegions[region];
+ const panelOpen = region === 'center' || project.layout.panels[region === 'left' ? 'isLeftOpen' : 'isBottomOpen'];
+
+ return panelOpen && !isCollapsed && instanceIds.includes(activeInstanceId) && isWorkflow(activeInstanceId)
+ ? activeInstanceId
+ : null;
+ };
+ const fromGraph =
+ target?.kind === 'floating'
+ ? isWorkflow(target.instanceId)
+ : (target?.region === 'center' || target?.region === 'bottom') && visibleWorkflow(target.region) !== null;
+ const floatingWorkflow = Object.keys(project.floatingWidgets ?? {}).find(isWorkflow);
+ const region = fromGraph ? 'left' : (graphRegions.find(visibleWorkflow) ?? graphRegions.find(hasWorkflow));
+
+ if (!region && floatingWorkflow) {
+ widgets.revealFloating(floatingWorkflow);
+ focus.focusFloating(floatingWorkflow);
+ return;
+ }
+
+ const destination = region ?? 'center';
+ const visibleInstance = visibleWorkflow(destination);
+
+ if (visibleInstance) {
+ focus.focusRegion(destination, undefined, visibleInstance);
+ return;
+ }
+
+ // Opening an unplaced view could dock the graph's floating window.
+ if (floatingWorkflow && !hasWorkflow(destination)) {
+ return;
+ }
+
+ const placedCenterGraph =
+ destination === 'center' ? project.widgetRegions.center.instanceIds.find(isWorkflow) : undefined;
+ if (placedCenterGraph) {
+ if (
+ getOpenableWidgetPlacement({
+ getWidgetsForRegion,
+ options: { preferredRegions: ['center'] },
+ typeId: 'workflow',
+ })
+ ) {
+ // Use the center picker's instance selection to keep the left panel in view.
+ widgets.select({ projectId: project.id, region: 'center', widgetId: placedCenterGraph });
+ focus.focusRegion('center', undefined, placedCenterGraph);
+ }
+ return;
+ }
+
+ // The Workflow preset uses a separate graph instance so opening the center leaves the form active.
+ if (!region && hasWorkflow('left')) {
+ const leftInstanceId = project.widgetRegions.left.activeInstanceId;
+ const graphInstanceId = ['workflow:center', 'workflow:bottom', 'workflow'].find(
+ (id) => id !== leftInstanceId && isWorkflow(id)
+ );
+
+ if (
+ graphInstanceId &&
+ getOpenableWidgetPlacement({
+ getWidgetsForRegion,
+ options: { preferredRegions: ['center'] },
+ typeId: 'workflow',
+ })
+ ) {
+ widgets.toggle({ projectId: project.id, region: 'center', widgetId: graphInstanceId });
+ focus.focusRegion('center', undefined, graphInstanceId);
+ }
+ return;
+ }
+
+ const opened = openWidgetPlacement({
+ getWidgetsForRegion,
+ options: { preferredRegions: [destination] },
+ projectId: project.id,
+ typeId: 'workflow',
+ widgets,
+ });
+
+ if (opened.ok) {
+ const { activeInstanceId } = queries.getSnapshot().activeProject.widgetRegions[destination];
+ focus.focusRegion(destination, undefined, activeInstanceId);
+ }
+ };
+
useMountEffect(() =>
commandApi.register({
handler: toggleCommandPalette,
@@ -425,6 +524,11 @@ export const useRegisterFirstPartyCommands = () => {
id: 'app.selectWorkflowsTab',
title: 'Open Workflow editor',
}),
+ commandApi.register({
+ handler: switchWorkflowView,
+ id: 'app.switchWorkflowView',
+ title: 'Switch workflow view',
+ }),
commandApi.register({
handler: () => openModelManager({ projectId: queries.getSnapshot().activeProject.id }),
id: 'app.selectModelsTab',
diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.ts
index 43d7349f9c..359851c2c5 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/entries.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.ts
@@ -231,6 +231,7 @@ const APP_COMMAND_GROUPS: Record<string, string> = {
'app.selectQueueTab': 'Navigation',
'app.selectUpscalingTab': 'Navigation',
'app.selectWorkflowsTab': 'Navigation',
+ 'app.switchWorkflowView': 'Workflows',
'app.toggleLeftPanel': 'Layout',
'app.togglePanels': 'Layout',
'app.togglePreview': 'Layout',