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
fix(canvas): select a text layer when its edit session opens
Josh Corbette608aa8749e3
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.tsindex acf5c103a5..91599ecf33 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts@@ -16472,6 +16472,26 @@ describe('text edit session', () => {engine.lifecycle.dispose();});+ it('opening an edit on an unselected text layer selects it, so pane edits outlive the session', () => {+ const { dispatch, engine } = makeEngine(textDoc({ selectedLayerId: null }));+ engine.tools.setTool('text');+ dispatch.mockClear();+ engine.layers.openTextEdit('txt1');+ expect(engine.stores.textEditSession.get()?.layerId).toBe('txt1');+ expect(dispatch).toHaveBeenCalledWith({ id: 'txt1', type: 'setCanvasSelectedLayer' });+ engine.lifecycle.dispose();+ });++ it('opening an edit on the selected text layer dispatches nothing', () => {+ const { dispatch, engine } = makeEngine(textDoc());+ engine.tools.setTool('text');+ dispatch.mockClear();+ engine.layers.openTextEdit('txt1');+ expect(engine.stores.textEditSession.get()?.layerId).toBe('txt1');+ expect(dispatch).not.toHaveBeenCalled();+ engine.lifecycle.dispose();+ });+it('edit-mode commit dispatches ONE updateCanvasLayerSource with the exact inverse', () => {const { dispatch, engine, layerActions } = makeEngine(textDoc());engine.tools.setTool('text');diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.tsindex ca7ea271e2..19761b8a8d 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts@@ -2566,7 +2566,14 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreCconst setTextEditContentReader = (reader: (() => string) | null): void =>editingController.text.setContentReader(reader);const openTextCreate = (point: Vec2): void => editingController.text.openCreate(point);- const openTextEdit = (layerId: string): void => editingController.text.openEdit(layerId);+ // The pane keeps styling the layer after the portal's blur commits the+ // session, so opening an edit also makes that layer the document selection.+ const openTextEdit = (layerId: string): void => {+ editingController.text.openEdit(layerId);+ if (stores.textEditSession.get()?.layerId === layerId && mirror.getDocument()?.selectedLayerId !== layerId) {+ dispatchCanvasMutation({ id: layerId, type: 'setCanvasSelectedLayer' });+ }+ };const updateTextEditStyle = (patch: TextStylePatch): void => editingController.text.updateStyle(patch);const cancelTextEdit = (): void => editingController.text.cancel();const commitTextEdit = (content: string, styleChanges?: TextStylePatch): StructuralCommitResult | null =>