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(ui): forget a floating window's focus once it docks or closes

Josh Corbett774a2c7c2cae
diff --git a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.browser.test.tsx
index 27d25437b8..7500c0837e 100644
--- a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.browser.test.tsx
@@ -166,6 +166,20 @@ describe('WorkbenchFocusProvider', () => {
expect(api.getTarget()).toBeNull();
});
+ it('does not hand focus back to a window that floats again without being focused', async () => {
+ const { commands } = runtimeMocks.store;
+ await render(true);
+ await press('window');
+
+ // The focused window leaves — as a preset applied in the same project can make it — and a later change floats
+ // the same instance again.
+ await act(() => commands.widgets.dockFloating('image-map'));
+ await act(() => commands.widgets.float('image-map'));
+
+ expect(runtimeMocks.store.getSnapshot().activeProject.floatingWidgets?.['image-map']).toBeDefined();
+ expect(api.getTarget()).toBeNull();
+ });
+
it('abandons a pending move when the workbench unmounts', async () => {
await render(false);
const move = api.focusFloating;
diff --git a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
index 6516431931..300d413811 100644
--- a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
+++ b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
@@ -26,7 +26,7 @@ export const WorkbenchRuntime = () => {
/**
* Owns workbench focus for everything below it — the shell and the hotkey runtime read the same target. Focus is
* transient: it is forgotten, along with any focus move still in flight, when the project on screen changes, the
- * account changes, or the workbench unmounts.
+ * account changes, or the workbench unmounts, and a window's focus is forgotten once it docks or closes.
*
* It lives in this module, beside the other workbench lifecycle adapter, because the editor's startup module set
* is pinned by the architecture performance gate; a module of its own would have to be added to that baseline.
@@ -49,6 +49,8 @@ export const WorkbenchFocusProvider = ({ children }: { children: ReactNode }) =>
if (nextProjectId !== projectId) {
projectId = nextProjectId;
controller.clear();
+ } else {
+ controller.forgetClosedWindow();
}
});
const unregister = registerAccountOwnedResource({ clear: controller.clear, name: 'workbench-focus' });
diff --git a/invokeai/frontend/webv2/src/workbench/focusRegions.tsx b/invokeai/frontend/webv2/src/workbench/focusRegions.tsx
index 550ebe7ec8..ec8e25c690 100644
--- a/invokeai/frontend/webv2/src/workbench/focusRegions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/focusRegions.tsx
@@ -34,6 +34,11 @@ export interface WorkbenchFocusController {
* widget, focus moves into the region as it stands.
*/
focusRegion(region: WidgetRegion, typeId?: string): void;
+ /**
+ * Forget a window target whose window has docked or closed. It already reads as null; forgetting it keeps the
+ * same instance from taking focus back without being focused, should a preset or undo float it again.
+ */
+ forgetClosedWindow(): void;
/** The focus target, or null once it no longer describes something on screen in this project and account. */
getTarget(): WorkbenchFocusTarget | null;
subscribe(listener: () => void): () => void;
@@ -74,8 +79,8 @@ export const createWorkbenchFocusController = ({
}
};
// The one place a target is judged. The owner clears eagerly on project and account changes, which is what
- // notifies subscribers and stops moves; this read-time check covers the instant between such a change and that
- // clear, and a window that docked or closed without anything else taking focus.
+ // notifies subscribers and stops moves, and forgets a closed window on the next workbench change; this read-time
+ // check covers the instant between such a change and the owner's response.
const getTarget = (): WorkbenchFocusTarget | null =>
entry &&
entry.projectId === getProjectId() &&
@@ -184,6 +189,11 @@ export const createWorkbenchFocusController = ({
return null;
}),
+ forgetClosedWindow: () => {
+ if (entry?.target.kind === 'floating' && !isFloating(entry.target.instanceId)) {
+ entry = null;
+ }
+ },
getTarget,
subscribe: (listener) => {
listeners.add(listener);