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): make the Invoke route follow the panel you bring to the front

Lincoln Stein5a8d292bc061
diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
index 9f255fc3a1..855b5b5762 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialog.tsx
@@ -420,7 +420,7 @@ const BehaviorSection = () => {
<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."
+ description="Switch the Invoke source and destination to match the surface you are editing or bring to the front. Locked sources and destinations are never changed."
label="Auto-switch Invoke route"
onChange={updateAutoSwitchInvocationRoute}
/>
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index ceb4e65c25..c71841d158 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -146,6 +146,7 @@ import {
type CanvasStagingSlot,
} from './canvasStagingView';
import { cascadeDefaultGeometry, clampSizeToMinimum, nextStackOrder } from './floatingWindows';
+import { getSourceIdForWidgetTypeId } from './graphWidgets';
import {
defaultInvocationRoute,
isInvocationRouteValid,
@@ -2352,6 +2353,70 @@ const applyAutoRouteForEdit = (
const applyAutoRouteForGenerateEdit = (project: Project, context: WorkbenchReducerContext): Project =>
project.invocation.sourceId === 'canvas' ? project : applyAutoRouteForEdit(project, 'generate', context);
+/**
+ * Bringing a graph-bearing widget to the front is as strong a statement of
+ * intent as editing one: someone who clicks the Video tab and presses Invoke
+ * means the video parameters, not whichever surface they last touched. Reveal
+ * therefore feeds the same policy as an edit, through the same preference and
+ * lock gates, so the surface in front of you is the surface that runs.
+ *
+ * Non-graph widgets (gallery, layers, ...) resolve to no source and leave the
+ * route alone, and generate keeps its canvas exception for the reason given
+ * above -- the canvas parameter panel *is* the generate widget, so revealing it
+ * must not steal the route from an active canvas source.
+ */
+const applyAutoRouteForWidgetReveal = (
+ project: Project,
+ typeId: WidgetTypeId | undefined,
+ context: WorkbenchReducerContext
+): Project => {
+ const sourceId = typeId ? getSourceIdForWidgetTypeId(typeId) : null;
+
+ if (!sourceId) {
+ return project;
+ }
+
+ return sourceId === 'generate'
+ ? applyAutoRouteForGenerateEdit(project, context)
+ : applyAutoRouteForEdit(project, sourceId, context);
+};
+
+/** `applyAutoRouteForWidgetReveal` for the instance-addressed reveal actions. */
+const applyAutoRouteForRevealedInstance = (
+ project: Project,
+ instanceId: WidgetInstanceId,
+ context: WorkbenchReducerContext
+): Project => applyAutoRouteForWidgetReveal(project, project.widgetInstances[instanceId]?.typeId, context);
+
+/**
+ * Reveal for the paths where the front widget changes as a *consequence* of
+ * something else — closing a tab, dragging one out of a rail, reordering — as
+ * opposed to the paths where the gesture names the widget outright.
+ *
+ * Only an actual change of the visible front widget counts. Closing a
+ * background tab leaves the same panel in front and must not re-target Invoke,
+ * and a region that ends collapsed (or whose `activeInstanceId` is left
+ * dangling by the last removal) has revealed nothing at all.
+ */
+const applyAutoRouteForRegionFront = (
+ project: Project,
+ previousRegion: WidgetRegionState,
+ region: WidgetRegion,
+ context: WorkbenchReducerContext
+): Project => {
+ const nextRegion = project.widgetRegions[region];
+
+ if (
+ nextRegion.isCollapsed ||
+ nextRegion.activeInstanceId === previousRegion.activeInstanceId ||
+ !nextRegion.instanceIds.includes(nextRegion.activeInstanceId)
+ ) {
+ return project;
+ }
+
+ return applyAutoRouteForRevealedInstance(project, nextRegion.activeInstanceId, context);
+};
+
const compileInvocationSnapshot = (
project: Project,
route: InvocationRoute,
@@ -3547,21 +3612,25 @@ export const __workbenchReducerInternal = (
// must never render in a panel and a floating window at once.
const { [instanceId]: _floated, ...floatingWidgets } = project.floatingWidgets ?? {};
- return {
- ...project,
- floatingWidgets,
- layout: openPanelForRegion(project.layout, action.region),
- widgetInstances,
- widgetRegions: {
- ...project.widgetRegions,
- [action.region]: {
- ...region,
- activeInstanceId: instanceId,
- instanceIds,
- isCollapsed: false,
+ return applyAutoRouteForWidgetReveal(
+ {
+ ...project,
+ floatingWidgets,
+ layout: openPanelForRegion(project.layout, action.region),
+ widgetInstances,
+ widgetRegions: {
+ ...project.widgetRegions,
+ [action.region]: {
+ ...region,
+ activeInstanceId: instanceId,
+ instanceIds,
+ isCollapsed: false,
+ },
},
},
- };
+ action.widgetId,
+ context
+ );
});
}
case 'selectRegionWidget': {
@@ -3569,30 +3638,56 @@ export const __workbenchReducerInternal = (
const region = project.widgetRegions[action.region];
if (action.region === 'center') {
- return {
+ return applyAutoRouteForRevealedInstance(
+ {
+ ...project,
+ widgetRegions: {
+ ...project.widgetRegions,
+ center: { ...region, activeInstanceId: action.widgetId, isCollapsed: false },
+ },
+ },
+ action.widgetId,
+ context
+ );
+ }
+
+ // Clicking the already-active tab toggles the rail's disclosure rather
+ // than switching tabs. Expanding it puts that panel back on screen and
+ // is a reveal like any other; collapsing it puts nothing in front, so
+ // the route stays exactly where it is.
+ if (region.activeInstanceId === action.widgetId) {
+ const disclosed = {
...project,
+ layout: openPanelForRegion(project.layout, action.region),
widgetRegions: {
...project.widgetRegions,
- center: { ...region, activeInstanceId: action.widgetId, isCollapsed: false },
+ [action.region]: { ...region, isCollapsed: !region.isCollapsed },
},
};
- }
- const widgetRegion =
- region.activeInstanceId === action.widgetId
- ? { ...region, isCollapsed: !region.isCollapsed }
- : { ...region, activeInstanceId: action.widgetId, isCollapsed: false };
+ return region.isCollapsed
+ ? applyAutoRouteForRevealedInstance(disclosed, action.widgetId, context)
+ : disclosed;
+ }
- return {
- ...project,
- layout: openPanelForRegion(project.layout, action.region),
- widgetRegions: { ...project.widgetRegions, [action.region]: widgetRegion },
- };
+ return applyAutoRouteForRevealedInstance(
+ {
+ ...project,
+ layout: openPanelForRegion(project.layout, action.region),
+ widgetRegions: {
+ ...project.widgetRegions,
+ [action.region]: { ...region, activeInstanceId: action.widgetId, isCollapsed: false },
+ },
+ },
+ action.widgetId,
+ context
+ );
});
}
case 'toggleRegionWidget': {
- return updateProjectById(state, action.projectId ?? state.activeProjectId, (project) =>
- updateProjectWidgetRegion(project, action.region, (region) => {
+ return updateProjectById(state, action.projectId ?? state.activeProjectId, (project) => {
+ const previousRegion = project.widgetRegions[action.region];
+ const nextProject = updateProjectWidgetRegion(project, action.region, (region) => {
const isEnabled = region.instanceIds.includes(action.widgetId);
if (action.region === 'center' && isEnabled && region.instanceIds.length === 1) {
@@ -3610,8 +3705,20 @@ export const __workbenchReducerInternal = (
instanceIds,
isCollapsed: action.region === 'center' ? false : instanceIds.length === 0 ? true : region.isCollapsed,
};
- })
- );
+ });
+
+ // A refused toggle (the work surface keeping its last view) must stay a
+ // no-op down to object identity: the persistence layer treats any new
+ // `projects` reference as a change worth autosaving.
+ if (nextProject === project) {
+ return project;
+ }
+
+ // Closing the front tab promotes a new one, which is a reveal; closing
+ // a background tab changes nothing on screen and must leave the route
+ // alone. `applyAutoRouteForRegionFront` draws exactly that line.
+ return applyAutoRouteForRegionFront(nextProject, previousRegion, action.region, context);
+ });
}
case 'floatWidget': {
return updateActiveProject(state, (project) => {
@@ -3646,25 +3753,31 @@ export const __workbenchReducerInternal = (
stackOrder: nextStackOrder(project.floatingWidgets),
};
- return {
- ...project,
- floatingWidgets: { ...project.floatingWidgets, [action.instanceId]: floating },
- widgetRegions: {
- ...project.widgetRegions,
- [hostRegionId]: {
- ...hostRegion,
- activeInstanceId:
- hostRegion.activeInstanceId === action.instanceId && fallbackInstanceId
- ? fallbackInstanceId
- : hostRegion.activeInstanceId,
- instanceIds,
- // Floating the last widget out of a rail leaves nothing to show,
- // so the rail collapses rather than standing open and empty —
- // the same repair `toggleRegionWidget` makes.
- isCollapsed: instanceIds.length === 0 ? true : hostRegion.isCollapsed,
+ return applyAutoRouteForRevealedInstance(
+ {
+ ...project,
+ floatingWidgets: { ...project.floatingWidgets, [action.instanceId]: floating },
+ widgetRegions: {
+ ...project.widgetRegions,
+ [hostRegionId]: {
+ ...hostRegion,
+ activeInstanceId:
+ hostRegion.activeInstanceId === action.instanceId && fallbackInstanceId
+ ? fallbackInstanceId
+ : hostRegion.activeInstanceId,
+ instanceIds,
+ // Floating the last widget out of a rail leaves nothing to show,
+ // so the rail collapses rather than standing open and empty —
+ // the same repair `toggleRegionWidget` makes.
+ isCollapsed: instanceIds.length === 0 ? true : hostRegion.isCollapsed,
+ },
},
},
- };
+ // The window lands on top of everything, so it is the revealed
+ // surface — not the tab the rail promotes behind it.
+ action.instanceId,
+ context
+ );
});
}
case 'dockFloatingWidget': {
@@ -3681,20 +3794,24 @@ export const __workbenchReducerInternal = (
? region.instanceIds
: insertAtReturnIndex(region.instanceIds, action.instanceId, floating.returnIndex);
- return {
- ...project,
- floatingWidgets: remaining,
- layout: openPanelForRegion(project.layout, floating.returnRegion),
- widgetRegions: {
- ...project.widgetRegions,
- [floating.returnRegion]: {
- ...region,
- activeInstanceId: action.instanceId,
- instanceIds,
- isCollapsed: false,
+ return applyAutoRouteForRevealedInstance(
+ {
+ ...project,
+ floatingWidgets: remaining,
+ layout: openPanelForRegion(project.layout, floating.returnRegion),
+ widgetRegions: {
+ ...project.widgetRegions,
+ [floating.returnRegion]: {
+ ...region,
+ activeInstanceId: action.instanceId,
+ instanceIds,
+ isCollapsed: false,
+ },
},
},
- };
+ action.instanceId,
+ context
+ );
});
}
case 'setFloatingWidgetGeometry': {
@@ -3749,6 +3866,12 @@ export const __workbenchReducerInternal = (
const floating = project.floatingWidgets?.[action.instanceId];
const topOrder = nextStackOrder(project.floatingWidgets) - 1;
+ // `focusFloatingWidget` is bound to `onPointerDownCapture` on the window
+ // root, so it fires on every scroll, drag, and button press inside the
+ // window — not just on a raise. Routing therefore stays behind this
+ // shortcut: raising a window reveals it, but touching the window that
+ // is already on top reveals nothing and must not re-target Invoke or
+ // dirty the project.
if (!floating || floating.stackOrder === topOrder) {
return project;
}
@@ -3768,7 +3891,7 @@ export const __workbenchReducerInternal = (
floatingWidgets[action.instanceId] = { ...floating, stackOrder: below.length + 1 };
- return { ...project, floatingWidgets };
+ return applyAutoRouteForRevealedInstance({ ...project, floatingWidgets }, action.instanceId, context);
});
}
case 'moveWidgetInstance': {
@@ -3778,37 +3901,50 @@ export const __workbenchReducerInternal = (
const nextFromInstanceIds = fromRegion.instanceIds.filter((instanceId) => instanceId !== action.instanceId);
const nextToInstanceIds = insertAt(toRegion.instanceIds, action.instanceId, action.toIndex);
- return {
- ...project,
- layout: openPanelForRegion(project.layout, action.toRegion),
- widgetRegions: {
- ...project.widgetRegions,
- [action.fromRegion]: {
- ...fromRegion,
- activeInstanceId:
- fromRegion.activeInstanceId === action.instanceId
- ? (nextFromInstanceIds[0] ?? fromRegion.activeInstanceId)
- : fromRegion.activeInstanceId,
- instanceIds: nextFromInstanceIds,
- isCollapsed:
- action.fromRegion === 'center' ? false : nextFromInstanceIds.length === 0 || fromRegion.isCollapsed,
- },
- [action.toRegion]: {
- ...toRegion,
- activeInstanceId: action.instanceId,
- instanceIds: nextToInstanceIds,
- isCollapsed: false,
+ return applyAutoRouteForRevealedInstance(
+ {
+ ...project,
+ layout: openPanelForRegion(project.layout, action.toRegion),
+ widgetRegions: {
+ ...project.widgetRegions,
+ [action.fromRegion]: {
+ ...fromRegion,
+ activeInstanceId:
+ fromRegion.activeInstanceId === action.instanceId
+ ? (nextFromInstanceIds[0] ?? fromRegion.activeInstanceId)
+ : fromRegion.activeInstanceId,
+ instanceIds: nextFromInstanceIds,
+ isCollapsed:
+ action.fromRegion === 'center' ? false : nextFromInstanceIds.length === 0 || fromRegion.isCollapsed,
+ },
+ [action.toRegion]: {
+ ...toRegion,
+ activeInstanceId: action.instanceId,
+ instanceIds: nextToInstanceIds,
+ isCollapsed: false,
+ },
},
},
- };
+ // The dragged widget lands expanded and selected in the target
+ // region; the tab the source region promotes behind it did not move.
+ action.instanceId,
+ context
+ );
});
}
case 'reorderWidgetInstances': {
- return updateActiveWidgetRegion(state, action.region, (region) => ({
- ...region,
- activeInstanceId: action.activeInstanceId ?? region.activeInstanceId,
- instanceIds: action.instanceIds,
- }));
+ return updateActiveProject(state, (project) => {
+ const previousRegion = project.widgetRegions[action.region];
+ const nextProject = updateProjectWidgetRegion(project, action.region, (region) => ({
+ ...region,
+ activeInstanceId: action.activeInstanceId ?? region.activeInstanceId,
+ instanceIds: action.instanceIds,
+ }));
+
+ // A reorder that also changes which tab is selected reveals that tab;
+ // a pure reorder leaves the same panel in front and must not re-route.
+ return applyAutoRouteForRegionFront(nextProject, previousRegion, action.region, context);
+ });
}
case 'setRegionWidgetCollapsed': {
if (action.region === 'center') {
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
index 127b799335..16cec9fba4 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
@@ -101,3 +101,235 @@ describe('auto invocation route switching with the preference off', () => {
expect(project?.invocation).toMatchObject({ destination: 'gallery', sourceId: 'generate' });
});
});
+
+type State = ReturnType<typeof createInitialWorkbenchState>;
+
+const getProject = (state: State) => state.projects.find((project) => project.id === state.activeProjectId)!;
+const getInvocation = (state: State) => getProject(state).invocation;
+const getRegion = (state: State, region: 'left' | 'right' | 'center' | 'bottom') =>
+ getProject(state).widgetRegions[region];
+
+describe('auto invocation route switching on widget reveal', () => {
+ it('follows the rail tab that is brought to the front', () => {
+ let state = createInitialWorkbenchState();
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'generate' });
+
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getInvocation(state)).toMatchObject({ destination: 'gallery', sourceId: 'video' });
+
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'generate' });
+
+ expect(getInvocation(state)).toMatchObject({ destination: 'gallery', sourceId: 'generate' });
+ });
+
+ it('routes when a collapsed rail is expanded back onto a graph widget, but not when it is collapsed', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+ // Collapsing the rail puts nothing in front, so the route must not move.
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getRegion(state, 'left').isCollapsed).toBe(true);
+
+ state = workbenchReducer(state, { sourceId: 'generate', type: 'setInvocationSource' });
+ // Expanding it puts the Video panel back on screen — that is a reveal.
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getRegion(state, 'left').isCollapsed).toBe(false);
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+
+ state = workbenchReducer(state, { sourceId: 'generate', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getRegion(state, 'left').isCollapsed).toBe(true);
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'generate' });
+ });
+
+ it('leaves the route alone when a background tab is closed', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { sourceId: 'workflow', type: 'setInvocationSource' });
+ // `video` is not the front tab, so closing it reveals nothing.
+ state = workbenchReducer(state, { region: 'left', type: 'toggleRegionWidget', widgetId: 'video' });
+
+ expect(getRegion(state, 'left').instanceIds).not.toContain('video');
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'workflow' });
+ });
+
+ it('follows the tab promoted when the front tab is closed', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+
+ state = workbenchReducer(state, { region: 'left', type: 'toggleRegionWidget', widgetId: 'video' });
+
+ const promoted = getRegion(state, 'left').activeInstanceId;
+
+ expect(promoted).not.toBe('video');
+ expect(getInvocation(state)).toMatchObject({ sourceId: promoted });
+ });
+
+ it('never routes to a widget that is left dangling by the last removal', () => {
+ let state = createInitialWorkbenchState();
+
+ for (const widgetId of getRegion(state, 'left').instanceIds) {
+ state = workbenchReducer(state, { region: 'left', type: 'toggleRegionWidget', widgetId });
+ }
+
+ const region = getRegion(state, 'left');
+
+ expect(region.instanceIds).toEqual([]);
+ // The route is left where it was rather than pointed at the emptied rail;
+ // route validation refuses an unmounted source separately.
+ expect(region.instanceIds).not.toContain(getInvocation(state).sourceId);
+ });
+
+ it('keeps a refused close a no-op down to object identity', () => {
+ let state = createInitialWorkbenchState();
+ const centerIds = [...getRegion(state, 'center').instanceIds];
+
+ for (const widgetId of centerIds.slice(1)) {
+ state = workbenchReducer(state, { region: 'center', type: 'toggleRegionWidget', widgetId });
+ }
+
+ state = workbenchReducer(state, { sourceId: 'video', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { destination: 'gallery', type: 'setInvocationDestination' });
+
+ const before = state;
+ const beforeProject = getProject(state);
+
+ // The work surface refuses to give up its last view; the whole dispatch
+ // must therefore change nothing, including the invoke route.
+ state = workbenchReducer(state, { region: 'center', type: 'toggleRegionWidget', widgetId: centerIds[0]! });
+
+ expect(state).toBe(before);
+ expect(getProject(state)).toBe(beforeProject);
+ expect(getInvocation(state)).toMatchObject({ destination: 'gallery', sourceId: 'video' });
+ });
+
+ it('does not route when a widget is added to a collapsed rail', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { region: 'bottom', type: 'setRegionWidgetCollapsed', isCollapsed: true });
+ state = workbenchReducer(state, { region: 'bottom', type: 'toggleRegionWidget', widgetId: 'workflow:bottom' });
+
+ expect(getRegion(state, 'bottom').isCollapsed).toBe(true);
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'generate' });
+ });
+
+ it('never lets a revealed generate widget steal the route from Canvas', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { sourceId: 'canvas', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'generate' });
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'canvas' });
+ });
+
+ it('ignores reveals of widgets that are not invocation sources', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+ state = workbenchReducer(state, { region: 'right', type: 'selectRegionWidget', widgetId: 'gallery' });
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+ });
+
+ it('respects the source lock and the preference', () => {
+ let locked = createInitialWorkbenchState();
+
+ locked = workbenchReducer(locked, { type: 'toggleSourceLock' });
+ locked = workbenchReducer(locked, { region: 'left', type: 'selectRegionWidget', widgetId: 'video' });
+
+ expect(getInvocation(locked)).toMatchObject({ sourceId: 'generate' });
+
+ let preferenceOffState = createInitialWorkbenchState();
+
+ preferenceOffState = workbenchReducer(
+ preferenceOffState,
+ { region: 'left', type: 'selectRegionWidget', widgetId: 'video' },
+ preferenceOff
+ );
+
+ expect(getInvocation(preferenceOffState)).toMatchObject({ sourceId: 'generate' });
+ });
+
+ it('follows a widget opened into a region', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { region: 'left', type: 'openRegionWidget', widgetId: 'video' });
+
+ expect(getInvocation(state)).toMatchObject({ destination: 'gallery', sourceId: 'video' });
+ });
+
+ it('follows a widget floated out, raised, or docked back', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { instanceId: 'video', type: 'floatWidget' });
+
+ expect(getInvocation(state)).toMatchObject({ destination: 'gallery', sourceId: 'video' });
+
+ state = workbenchReducer(state, { instanceId: 'upscale', type: 'floatWidget' });
+ state = workbenchReducer(state, { sourceId: 'generate', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { instanceId: 'video', type: 'focusFloatingWidget' });
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+
+ state = workbenchReducer(state, { sourceId: 'generate', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { instanceId: 'video', type: 'dockFloatingWidget' });
+
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+ });
+
+ it('does not re-route or dirty the project when the already-raised window is touched', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { instanceId: 'upscale', type: 'floatWidget' });
+ state = workbenchReducer(state, { sourceId: 'workflow', type: 'setInvocationSource' });
+
+ const before = state;
+
+ // Bound to `onPointerDownCapture`, so this fires on every scroll and click
+ // inside the window, not just on a raise.
+ state = workbenchReducer(state, { instanceId: 'upscale', type: 'focusFloatingWidget' });
+
+ expect(state).toBe(before);
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'workflow' });
+ });
+
+ it('follows a tab dragged into another region, and a reorder only when it changes the front tab', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, {
+ fromRegion: 'left',
+ instanceId: 'video',
+ toIndex: 0,
+ toRegion: 'right',
+ type: 'moveWidgetInstance',
+ });
+
+ expect(getRegion(state, 'right').activeInstanceId).toBe('video');
+ expect(getInvocation(state)).toMatchObject({ sourceId: 'video' });
+
+ const reordered = workbenchReducer(state, {
+ instanceIds: [...getRegion(state, 'left').instanceIds].reverse(),
+ region: 'left',
+ type: 'reorderWidgetInstances',
+ });
+
+ expect(getInvocation(reordered)).toMatchObject({ sourceId: 'video' });
+
+ const reselected = workbenchReducer(state, {
+ activeInstanceId: 'upscale',
+ instanceIds: [...getRegion(state, 'left').instanceIds],
+ region: 'left',
+ type: 'reorderWidgetInstances',
+ });
+
+ expect(getInvocation(reselected)).toMatchObject({ sourceId: 'upscale' });
+ });
+});