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
feat(webv2): reopen floating widgets where they last floated
Josh Corbett6f7d08626a05
diff --git a/docs/src/content/docs/Users Guide/01.Workbench/01.introduction.mdx b/docs/src/content/docs/Users Guide/01.Workbench/01.introduction.mdxindex e0be34a361..3bc93bd0d7 100644--- a/docs/src/content/docs/Users Guide/01.Workbench/01.introduction.mdx+++ b/docs/src/content/docs/Users Guide/01.Workbench/01.introduction.mdx@@ -71,6 +71,8 @@ The status bar along the bottom holds small chips. Hover over **Server Status**,- The dock button in the title bar, named for where the window came from (for example **Dock to right panel**), returns the panel to the place it floated from.- The panel's dashed rail icon keeps its place while the window floats. Click it to bring the window to the front and expand it; right-click it to dock or remove the panel.+A window remembers where it was. Dock or remove a floating panel and float it again later, and it reopens at the same position and size.+If the panel you float was also the only view in the center, the center shows where it went, with **Show window** and a dock button. Docking or removing the window gives the center its view back.A floating Preview is handy on the **Edit** layout: keep the canvas in the center and watch results in a small window beside your work.diff --git a/invokeai/frontend/webv2/ARCHITECTURE.md b/invokeai/frontend/webv2/ARCHITECTURE.mdindex 12db711c38..e651a14ecd 100644--- a/invokeai/frontend/webv2/ARCHITECTURE.md+++ b/invokeai/frontend/webv2/ARCHITECTURE.md@@ -113,6 +113,8 @@ A project places each widget instance in regions (`widgetRegions`) or in a float- **Region requests never discard a window.** Selecting, moving, or reordering an instance a region does not hold is a no-op, and so is enabling an instance that floats. Opening a widget type whose instance floats restores its return placement first, then opens the requested one, and auto-routes once.- **One normalization.** `normalizeFloatingPlacement` runs on project hydration, on stored presets, on preset application, and inside preset comparison (which includes `returnIndex`), so an applied preset always matches the snapshot it came from. It is idempotent. Indices stored before markers were counted are read deterministically (ascending, ties by instance id, missing ones appended); that is best-effort and does not reconstruct the original arrangement.+- **A closed window leaves its geometry behind.** When a window closes — docked, removed, or closed by a preset or an undo — its position and size move to `Project.lastFloatingGeometry` (`rememberClosedWindows`); floating the instance again takes them back out and reopens the window there, windowed, and only a first float cascades. The float command passes the viewport, so a rectangle remembered in a larger one is brought wholly on screen rather than reopening as a sliver. The memory holds only instances that exist and are not floating now, in every state the reducer produces, so a save is exactly what a load reads back. It is persisted with the project and validated on load, but it is not layout: preset snapshots, drift comparison, and undo snapshots do not carry it.+The rails subscribe to placement only (`getWidgetPlacementProject` projects `floatingPlacements`), so a window's geometry, mode, and stacking change without re-rendering them. A marker is not a tab: it stays out of the sortable list, activating it raises and expands its window, and Dock and Remove live in its context menu. Marker UI exists only on the left and right rails.### Focusdiff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.tsindex f412f59b8d..03f14bc530 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts@@ -16,6 +16,7 @@ import {doesProjectMatchLayoutPreset,resolveSavedLayoutPreset,} from './layoutPresetSnapshots';+import { serializeProjectDocumentV3 } from './projects/projectDocument';import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from './widgetPlacementMeta';import { createWidgetRegionViewModelFromState } from './widgetRegionViewModel';import { getWidgetsForRegion } from './widgetRegistry';@@ -665,6 +666,199 @@ describe('revealFloatingWidget', () => {});});+describe('remembered window geometry', () => {+ const PLACED = { heightPx: 360, widthPx: 480, x: 700, y: 220 };+ const moveGallery = (state: WorkbenchState): WorkbenchState =>+ workbenchReducer(state, { instanceId: 'gallery', type: 'setFloatingWidgetGeometry', ...PLACED });++ it('reopens a docked window where it last floated instead of cascading it again', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });++ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });++ state = workbenchReducer(state, { instanceId: 'gallery', type: 'floatWidget' });+ const project = getActiveProject(state);++ expect(project.floatingWidgets?.gallery).toMatchObject({ ...PLACED, mode: 'windowed' });+ // While the window is open its geometry is its own state; nothing stale is kept beside it.+ expect(project.lastFloatingGeometry).toBeUndefined();+ });++ it('reopens a removed window there too, once its widget is back on the rail and floated', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'closeFloatingWidget' });+ state = workbenchReducer(state, { region: 'right', type: 'openRegionWidget', widgetId: 'gallery' });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'floatWidget' });++ expect(getActiveProject(state).floatingWidgets?.gallery).toMatchObject(PLACED);+ });++ it('remembers each window on its own, and gives a first float the next cascade slot', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ state = workbenchReducer(state, { instanceId: 'queue', type: 'floatWidget' });+ const project = getActiveProject(state);++ expect(project.floatingWidgets?.queue).toMatchObject(cascadeDefaultGeometry(0));+ expect(project.lastFloatingGeometry).toEqual({ gallery: PLACED });+ });++ it('survives a save and reload, through the durable project document', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ const document = JSON.parse(JSON.stringify(serializeProjectDocumentV3(getActiveProject(state)))) as Project;+ const reloaded = withActiveProject(state, () => normalizeWorkbenchProject(document));++ expect(getActiveProject(reloaded).lastFloatingGeometry).toEqual({ gallery: PLACED });+ expect(+ getActiveProject(workbenchReducer(reloaded, { instanceId: 'gallery', type: 'floatWidget' })).floatingWidgets+ ?.gallery+ ).toMatchObject(PLACED);+ });++ it('keeps only well-formed memory for instances that exist and are not floating now', () => {+ const project = getActiveProject(floatGallery());+ const normalized = normalizeWorkbenchProject({+ ...project,+ lastFloatingGeometry: {+ // Floating right now: the window's own geometry is the truth.+ gallery: PLACED,+ 'no-such-widget': PLACED,+ preview: { ...PLACED, x: Number.NaN },+ queue: { ...PLACED, heightPx: 1, widthPx: 1 },+ },+ } as Project);++ expect(normalized.lastFloatingGeometry).toEqual({+ queue: { ...PLACED, heightPx: FLOATING_MIN_HEIGHT_PX, widthPx: FLOATING_MIN_WIDTH_PX },+ });+ });++ it('reopens windowed at the windowed rectangle, whatever mode the window was closed in', () => {+ for (const mode of ['maximized', 'shaded'] as const) {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', mode, type: 'setFloatingWidgetMode' });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'floatWidget' });++ expect(getActiveProject(state).floatingWidgets?.gallery).toMatchObject({ ...PLACED, mode: 'windowed' });+ }+ });++ it('remembers the latest place a window was closed, not an earlier one', () => {+ const LATER = { heightPx: 300, widthPx: 420, x: 120, y: 80 };+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'floatWidget' });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'setFloatingWidgetGeometry', ...LATER });+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'closeFloatingWidget' });++ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: LATER });+ });++ it('remembers a window that an explicit open docks', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { region: 'right', type: 'openRegionWidget', widgetId: 'gallery' });++ expect(getActiveProject(state).floatingWidgets).toBeUndefined();+ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });+ });++ it('brings a window remembered in a larger viewport back on screen when it floats into a smaller one', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ // Remembered at x=700 with a 480px width; the viewport is now 720px wide (the same window at 200% zoom).+ state = workbenchReducer(state, {+ instanceId: 'gallery',+ type: 'floatWidget',+ viewport: { height: 450, width: 720 },+ });++ expect(getActiveProject(state).floatingWidgets?.gallery).toMatchObject({+ heightPx: 360,+ widthPx: 480,+ x: 720 - 480,+ y: 450 - 360,+ });+ });++ it('remembers a window a preset closes, and forgets the memory of one a preset opens', () => {+ // Saved with Gallery floating at its first place; then the window is moved and the plain layout applied.+ let state = workbenchReducer(floatGallery(), { presetId: 'compose', type: 'saveLayoutPreset' });+ const savedPlace = { ...cascadeDefaultGeometry(0) };+ state = moveGallery(state);+ state = workbenchReducer(state, { presetId: 'edit', type: 'applyPreset' });++ expect(getActiveProject(state).floatingWidgets).toBeUndefined();+ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });++ // Back to the layout that floats it: the window is the preset's, and no memory is kept beside it.+ state = workbenchReducer(state, { presetId: 'compose', type: 'applyPreset' });++ expect(getActiveProject(state).floatingWidgets?.gallery).toMatchObject(savedPlace);+ expect(getActiveProject(state).lastFloatingGeometry).toBeUndefined();+ });++ it('remembers a window an undo closes, and forgets the memory of one an undo reopens', () => {+ // The undoable step is a preset switch taken while Gallery floats.+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { presetId: 'edit', type: 'applyPreset' });+ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });++ state = workbenchReducer(state, { type: 'undoProjectChange' });++ // Undo reopened the window, so its geometry is the window's own again.+ expect(getActiveProject(state).floatingWidgets?.gallery).toMatchObject(PLACED);+ expect(getActiveProject(state).lastFloatingGeometry).toBeUndefined();++ state = workbenchReducer(state, { type: 'redoProjectChange' });++ expect(getActiveProject(state).floatingWidgets).toBeUndefined();+ expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });+ });++ it('always saves memory the way a reload would read it back', () => {+ // Persistence compares what it sent with the document as a reload reads it, as JSON. Anything a reload would+ // drop or reorder in these fields turns a lost response into a conflict.+ const placement = (project: Project): string => {+ const { floatingWidgets, lastFloatingGeometry } = serializeProjectDocumentV3(project);++ return JSON.stringify({ floatingWidgets, lastFloatingGeometry });+ };+ const savesCanonically = (state: WorkbenchState) => {+ const saved = serializeProjectDocumentV3(getActiveProject(state));+ const reloaded = normalizeWorkbenchProject(JSON.parse(JSON.stringify(saved)) as Project);++ expect(placement(reloaded)).toBe(placement(getActiveProject(state)));+ };+ let state = workbenchReducer(floatGallery(), { presetId: 'compose', type: 'saveLayoutPreset' });+ state = moveGallery(state);++ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ savesCanonically(state);+ // A preset that floats the docked window again.+ state = workbenchReducer(state, { presetId: 'compose', type: 'applyPreset' });+ savesCanonically(state);+ // A preset that closes it, then an undo that reopens it, then a redo that closes it again.+ state = workbenchReducer(state, { presetId: 'edit', type: 'applyPreset' });+ savesCanonically(state);+ state = workbenchReducer(state, { type: 'undoProjectChange' });+ savesCanonically(state);+ state = workbenchReducer(state, { type: 'redoProjectChange' });+ savesCanonically(state);+ });++ it('is not layout: floating, moving, and docking back leaves the saved preset matching', () => {+ let state = moveGallery(floatGallery());+ state = workbenchReducer(state, { instanceId: 'gallery', type: 'dockFloatingWidget' });+ const project = getActiveProject(state);++ expect(project.lastFloatingGeometry).toBeDefined();+ expect(doesProjectMatchLayoutPreset(project, resolveSavedLayoutPreset(state.account, 'compose'))).toBe(true);+ });+});+describe('pure helpers', () => {it('nextStackOrder starts at 1 and increments past the max', () => {expect(nextStackOrder(undefined)).toBe(1);diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.tsindex 0c4d0bff76..7cd5cd32ed 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts@@ -5,6 +5,7 @@ import type { FloatingWidgetState, WidgetRegion, WidgetRegionState } from './layimport {clampWindowToViewport,commitResizedAxes,+ fitWindowIntoViewport,FLOATING_MIN_HEIGHT_PX,FLOATING_MIN_WIDTH_PX,getRegionOrder,@@ -272,6 +273,25 @@ describe('commitResizedAxes', () => {});});+describe('fitWindowIntoViewport', () => {+ it('brings a rectangle remembered from a larger viewport wholly on screen, keeping its size', () => {+ const remembered = { heightPx: 360, widthPx: 480, x: 700, y: 520 };++ expect(fitWindowIntoViewport(remembered, { height: 450, width: 720 })).toEqual({ ...remembered, x: 240, y: 90 });+ // Larger than the viewport: pinned to the corner; CSS caps what is shown and the size is kept.+ expect(fitWindowIntoViewport({ ...remembered, widthPx: 2000 }, { height: 450, width: 720 })).toMatchObject({+ widthPx: 2000,+ x: 0,+ });+ expect(fitWindowIntoViewport({ ...remembered, x: -300, y: -20 }, { height: 900, width: 1440 })).toMatchObject({+ x: 0,+ y: 0,+ });+ // Already on screen: untouched.+ expect(fitWindowIntoViewport(remembered, { height: 900, width: 1440 })).toEqual(remembered);+ });+});+describe('clampWindowToViewport', () => {it('keeps a sliver of the width that is shown, not of a wider stored one', () => {// Shown no wider than the 600px viewport, so the left limit is 48 - 600, not 48 - 2000.diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.tsindex 41bb496c56..d3c0e28d71 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.ts@@ -1,4 +1,5 @@import type {+ FloatingWidgetGeometry,FloatingWidgetMode,FloatingWidgetState,WidgetRegion,@@ -24,12 +25,7 @@ const CASCADE_ORIGIN_PX = 96;const CASCADE_STEP_PX = 32;const CASCADE_WRAP = 8;-export interface FloatingGeometry {- x: number;- y: number;- widthPx: number;- heightPx: number;-}+export type FloatingGeometry = FloatingWidgetGeometry;export const nextStackOrder = (floatingWidgets: Record<WidgetInstanceId, FloatingWidgetState> | undefined): number =>Object.values(floatingWidgets ?? {}).reduce((max, state) => Math.max(max, state.stackOrder), 0) + 1;@@ -326,3 +322,88 @@ export const withoutFloatedInstances = (instanceIds,isCollapsed: instanceIds.length === 0 ? regionId !== 'center' : region.isCollapsed,});++/** The one shape remembered geometry is written in; persistence compares documents as JSON, key order included. */+const toRememberedGeometry = ({ heightPx, widthPx, x, y }: FloatingWidgetGeometry): FloatingWidgetGeometry => ({+ heightPx,+ widthPx,+ x,+ y,+});++/**+ * Keep the memory of closed windows in step with a change to the open ones, so it always reads the way+ * {@link normalizeLastFloatingGeometry} would leave it: a window that was open and no longer is leaves its+ * geometry behind, one that is open now has none (its geometry is its own state), and an instance that no longer+ * exists is forgotten. Returns the same memory when nothing changed, and undefined when nothing is remembered.+ */+export const rememberClosedWindows = (+ remembered: Record<WidgetInstanceId, FloatingWidgetGeometry> | undefined,+ before: Record<WidgetInstanceId, FloatingWidgetState> | undefined,+ after: Record<WidgetInstanceId, FloatingWidgetState> | undefined,+ hasInstance: (instanceId: WidgetInstanceId) => boolean = () => true+): Record<WidgetInstanceId, FloatingWidgetGeometry> | undefined => {+ const closed = Object.entries(before ?? {}).filter(([instanceId]) => !after?.[instanceId] && hasInstance(instanceId));+ const staleIds = Object.keys(remembered ?? {}).filter(+ (instanceId) => after?.[instanceId] !== undefined || !hasInstance(instanceId)+ );++ if (closed.length === 0 && staleIds.length === 0) {+ return remembered;+ }++ const next = { ...remembered };++ for (const instanceId of staleIds) {+ delete next[instanceId];+ }+ for (const [instanceId, geometry] of closed) {+ next[instanceId] = toRememberedGeometry(geometry);+ }++ return Object.keys(next).length > 0 ? next : undefined;+};++/**+ * Bring a remembered rectangle wholly into the viewport. The sliver policy suits a window that was already open+ * when the viewport shrank; a window the user has just asked to float should arrive where they can use it. The+ * size is left alone: CSS caps what is shown, and the stored size returns when there is room.+ */+export const fitWindowIntoViewport = (+ geometry: FloatingGeometry,+ viewport: { width: number; height: number }+): FloatingGeometry => ({+ ...geometry,+ x: Math.max(0, Math.min(geometry.x, viewport.width - Math.min(geometry.widthPx, viewport.width))),+ y: Math.max(0, Math.min(geometry.y, viewport.height - Math.min(geometry.heightPx, viewport.height))),+});++/**+ * Stored memory of where docked or closed windows last floated. Keeps well-formed geometry for instances that+ * exist and are not floating now — a floating window's geometry is its own state — and reports none as undefined.+ */+export const normalizeLastFloatingGeometry = (+ stored: unknown,+ hasInstance: (instanceId: WidgetInstanceId) => boolean,+ floatingWidgets: Record<WidgetInstanceId, FloatingWidgetState> | undefined+): Record<WidgetInstanceId, FloatingWidgetGeometry> | undefined => {+ if (!stored || typeof stored !== 'object') {+ return undefined;+ }++ const remembered: Record<WidgetInstanceId, FloatingWidgetGeometry> = {};++ for (const [instanceId, entry] of Object.entries(stored as Record<string, unknown>)) {+ if (!entry || typeof entry !== 'object' || !hasInstance(instanceId) || floatingWidgets?.[instanceId]) {+ continue;+ }++ const { heightPx, widthPx, x, y } = entry as Partial<FloatingWidgetGeometry>;++ if (isFiniteNumber(x) && isFiniteNumber(y) && isFiniteNumber(widthPx) && isFiniteNumber(heightPx)) {+ remembered[instanceId] = toRememberedGeometry(clampSizeToMinimum({ heightPx, widthPx, x, y }));+ }+ }++ return Object.keys(remembered).length > 0 ? remembered : undefined;+};diff --git a/invokeai/frontend/webv2/src/workbench/layoutContracts.ts b/invokeai/frontend/webv2/src/workbench/layoutContracts.tsindex 2241d80fb2..ec8e1129c3 100644--- a/invokeai/frontend/webv2/src/workbench/layoutContracts.ts+++ b/invokeai/frontend/webv2/src/workbench/layoutContracts.ts@@ -41,6 +41,9 @@ export interface FloatingWidgetState {stackOrder: number;}+/** Where a window sat and how large it was, kept after it docks or closes so floating it again reopens it there. */+export type FloatingWidgetGeometry = Pick<FloatingWidgetState, 'heightPx' | 'widthPx' | 'x' | 'y'>;+export interface WidgetRegionState {activeInstanceId: WidgetInstanceId;instanceIds: WidgetInstanceId[];diff --git a/invokeai/frontend/webv2/src/workbench/projectContracts.ts b/invokeai/frontend/webv2/src/workbench/projectContracts.tsindex 1dd05fe0f4..3f97958165 100644--- a/invokeai/frontend/webv2/src/workbench/projectContracts.ts+++ b/invokeai/frontend/webv2/src/workbench/projectContracts.ts@@ -5,6 +5,7 @@ import type { CanvasLoadRefusal } from './canvasLoadContracts';import type { GraphContract } from './graphContracts';import type { InvocationControllerState } from './invocationContracts';import type {+ FloatingWidgetGeometry,FloatingWidgetState,LayoutPreset,LayoutPresetId,@@ -37,6 +38,11 @@ export interface Project {widgetRegions: Record<WidgetRegion, WidgetRegionState>;/** Floating instances leave their region's instanceIds; absent in older projects means no floating windows. */floatingWidgets?: Record<WidgetInstanceId, FloatingWidgetState>;+ /**+ * The last window geometry of instances that are not floating now. It is a convenience, not layout: presets,+ * layout drift, and undo leave it out. Absent means nothing is remembered.+ */+ lastFloatingGeometry?: Record<WidgetInstanceId, FloatingWidgetGeometry>;widgetGraphs: Partial<Record<WidgetTypeId, GraphContract>>;canvas: CanvasStateContractV3;promptHistory: PromptHistoryItem[];diff --git a/invokeai/frontend/webv2/src/workbench/projects/projectDocument.ts b/invokeai/frontend/webv2/src/workbench/projects/projectDocument.tsindex 1ce0b3e5c8..fd7390232b 100644--- a/invokeai/frontend/webv2/src/workbench/projects/projectDocument.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/projectDocument.ts@@ -16,6 +16,7 @@ export type ProjectDocumentV3 = Omit<| 'floatingWidgets'| 'id'| 'invocation'+ | 'lastFloatingGeometry'| 'layout'| 'name'| 'promptHistory'@@ -24,10 +25,11 @@ export type ProjectDocumentV3 = Omit<| 'widgetInstances'| 'widgetRegions'>,- 'floatingWidgets'+ 'floatingWidgets' | 'lastFloatingGeometry'> & {documentSchemaVersion: typeof PROJECT_DOCUMENT_SCHEMA_VERSION;floatingWidgets?: Project['floatingWidgets'];+ lastFloatingGeometry?: Project['lastFloatingGeometry'];workflows: ProjectWorkflowCollection;};@@ -67,6 +69,7 @@ export const serializeProjectDocumentV3 = (project: Project): ProjectDocumentV3...(persistent.floatingWidgets ? { floatingWidgets: persistent.floatingWidgets } : {}),id: persistent.id,invocation: persistent.invocation,+ ...(persistent.lastFloatingGeometry ? { lastFloatingGeometry: persistent.lastFloatingGeometry } : {}),layout: persistent.layout,name: persistent.name,promptHistory: persistent.promptHistory,diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsxindex 652e392fa9..6d0656d744 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx@@ -127,7 +127,11 @@ describe('WidgetFloatButton', () => {});expect(floatMocks.flushWorkbenchDrafts).toHaveBeenCalled();- expect(floatMocks.float).toHaveBeenCalledWith('image-map-instance', 'right');+ // With the viewport it opens into, so a position remembered from a larger one is brought on screen.+ expect(floatMocks.float).toHaveBeenCalledWith('image-map-instance', 'right', {+ height: window.innerHeight,+ width: window.innerWidth,+ });expect(floatMocks.flushWorkbenchDrafts.mock.invocationCallOrder[0]).toBeLessThan(floatMocks.float.mock.invocationCallOrder[0]);diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsxindex 0feb9dd8c2..5913ff1d7d 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx@@ -172,7 +172,7 @@ export const WidgetFloatButton = ({}flushWorkbenchDrafts();- widgets.float(instanceId, dockableRegion);+ widgets.float(instanceId, dockableRegion, { height: window.innerHeight, width: window.innerWidth });focusFloating(instanceId);}, [dockableRegion, focusFloating, instanceId, widgets]);const canFloat = Boolean(manifest.allowFloating) && dockableRegion !== undefined;diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex d2f0418ca3..a166f4f6a1 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -184,10 +184,13 @@ import {import {cascadeDefaultGeometry,clampSizeToMinimum,+ fitWindowIntoViewport,getRegionOrder,isAwaitedCenterView,nextStackOrder,normalizeFloatingPlacement,+ normalizeLastFloatingGeometry,+ rememberClosedWindows,withoutFloatedInstances,writeRegionOrder,type RegionOrderSlot,@@ -288,6 +291,8 @@ type WorkbenchReducerAction =instanceId: WidgetInstanceId;/** The chrome the float was asked from; docking returns the window there. */region?: WidgetRegion;+ /** The viewport the window opens into, so a remembered position from a larger one is brought on screen. */+ viewport?: { width: number; height: number };}| { type: 'dockFloatingWidget'; instanceId: WidgetInstanceId }| { type: 'closeFloatingWidget'; instanceId: WidgetInstanceId }@@ -1217,6 +1222,14 @@ const restoreUndoSnapshot = (project: Project, snapshot: ProjectUndoSnapshot): P...project,// Restore floating windows with widgetRegions to avoid duplicate or orphaned placements.floatingWidgets: snapshot.floatingWidgets ? { ...snapshot.floatingWidgets } : undefined,+ // The memory is not part of the snapshot, but a window the undo closes is still remembered.+ lastFloatingGeometry: rememberClosedWindows(+ project.lastFloatingGeometry,+ project.floatingWidgets,+ snapshot.floatingWidgets,+ // The snapshot's instances replace the project's, so an instance created since is gone.+ (instanceId) => Object.hasOwn(snapshot.widgetInstances, instanceId)+ ),invocation: { ...snapshot.invocation },layout: { ...snapshot.layout, panels: { ...snapshot.layout.panels } },widgetGraphs: cloneWidgetGraphs(snapshot.widgetGraphs),@@ -1695,6 +1708,11 @@ const assembleWorkbenchProject = (canvas,events: isArriving ? [] : project.events.slice(0, PROJECT_EVENT_LIMIT),floatingWidgets: placement.floatingWidgets,+ lastFloatingGeometry: normalizeLastFloatingGeometry(+ (project as Partial<Project>).lastFloatingGeometry,+ (instanceId) => Object.hasOwn(widgetInstances, instanceId),+ placement.floatingWidgets+ ),// Resolve historical built-in preset ids to their current arrangements to avoid false layout drift.layout: { ...project.layout, presetId: resolveLayoutPresetId(project.layout.presetId) },promptHistory: normalizePromptHistory((project as Partial<Project>).promptHistory),@@ -1881,14 +1899,13 @@ const updateRegionOrder = (const before = getRegionOrder(regionId, region.instanceIds, project.floatingWidgets);const after = update(before);const markerIds = new Set(after.filter((slot) => slot.isFloating).map((slot) => slot.instanceId));- const remaining = before.reduce(- (floatingWidgets, slot) =>- slot.isFloating && !markerIds.has(slot.instanceId)- ? withoutFloatingWidget(floatingWidgets, slot.instanceId)- : floatingWidgets,- project.floatingWidgets- );+ const closedIds = before+ .filter((slot) => slot.isFloating && !markerIds.has(slot.instanceId))+ .map((slot) => slot.instanceId);+ const remaining = closedIds.reduce(withoutFloatingWidget, project.floatingWidgets);const order = writeRegionOrder(after, remaining);+ // A window that docks or closes leaves its geometry behind, so floating the instance again reopens it there.+ const lastFloatingGeometry = rememberClosedWindows(project.lastFloatingGeometry, project.floatingWidgets, remaining);const isMembershipUnchanged =order.instanceIds.length === region.instanceIds.length &&order.instanceIds.every((instanceId, index) => instanceId === region.instanceIds[index]);@@ -1897,12 +1914,13 @@ const updateRegionOrder = (if (isMembershipUnchanged) {return order.floatingWidgets === project.floatingWidgets? project- : { ...project, floatingWidgets: order.floatingWidgets };+ : { ...project, floatingWidgets: order.floatingWidgets, lastFloatingGeometry };}return {...project,floatingWidgets: order.floatingWidgets,+ lastFloatingGeometry,widgetRegions: { ...project.widgetRegions, [regionId]: { ...region, instanceIds: order.instanceIds } },};};@@ -2297,6 +2315,12 @@ const applyLayoutPresetToProject = (project: Project, preset: LayoutPreset): Proreturn {...project,floatingWidgets: snapshot.floatingWidgets,+ // Presets carry no memory of their own, but a window the preset closes is still remembered.+ lastFloatingGeometry: rememberClosedWindows(+ project.lastFloatingGeometry,+ project.floatingWidgets,+ snapshot.floatingWidgets+ ),layout: {...snapshot.layout,panels: { ...snapshot.layout.panels },@@ -3919,10 +3943,17 @@ export const __workbenchReducerInternal = (return project;}+ // The window reopens where it last floated, brought on screen if that was in a larger viewport; a first+ // float takes the next cascade slot.+ const remembered = project.lastFloatingGeometry?.[action.instanceId];let floatingWidgets: Record<WidgetInstanceId, FloatingWidgetState> | undefined = {...project.floatingWidgets,[action.instanceId]: {- ...cascadeDefaultGeometry(Object.keys(project.floatingWidgets ?? {}).length),+ ...(remembered+ ? action.viewport+ ? fitWindowIntoViewport(remembered, action.viewport)+ : remembered+ : cascadeDefaultGeometry(Object.keys(project.floatingWidgets ?? {}).length)),mode: 'windowed',returnRegion,stackOrder: nextStackOrder(project.floatingWidgets),@@ -3947,7 +3978,17 @@ export const __workbenchReducerInternal = (}return applyAutoRouteForRevealedInstance(- { ...project, floatingWidgets, widgetRegions },+ {+ ...project,+ floatingWidgets,+ // The memory is spent while the window is open: its geometry is the window's own state again.+ lastFloatingGeometry: rememberClosedWindows(+ project.lastFloatingGeometry,+ project.floatingWidgets,+ floatingWidgets+ ),+ widgetRegions,+ },// The window lands on top of everything, so it is the revealed// surface — not the tab the rail promotes behind it.action.instanceId,diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.tsindex 4e6de7fc6d..74d4636b05 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts@@ -426,8 +426,13 @@ const createCommands = (widgets: {dockFloating: command('dockFloatingWidget', (instanceId: string) => ({ instanceId })),closeFloating: command('closeFloatingWidget', (instanceId: string) => ({ instanceId })),- float: command('floatWidget', (instanceId: string, region?: ActionPayload<'floatWidget'>['region']) =>- region ? { instanceId, region } : { instanceId }+ float: command(+ 'floatWidget',+ (+ instanceId: string,+ region?: ActionPayload<'floatWidget'>['region'],+ viewport?: ActionPayload<'floatWidget'>['viewport']+ ) => ({ instanceId, ...(region ? { region } : {}), ...(viewport ? { viewport } : {}) })),raiseFloating: command('raiseFloatingWidget', (instanceId: string) => ({ instanceId })),move: command('moveWidgetInstance'),