diff options
author | bobzel <zzzman@gmail.com> | 2025-04-21 14:08:53 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-04-21 14:08:53 -0400 |
commit | 06bc78476ef050b8ce12a015a7d5492e01aa8cb8 (patch) | |
tree | aa3b01b88bfffd0658e7055b65d110bbbc16b243 /src/client/views/nodes/ImageBox.tsx | |
parent | 17e24e780b54f2f7015c0ca955c3aa5091bba19c (diff) |
added undo for outpaint
Diffstat (limited to 'src/client/views/nodes/ImageBox.tsx')
-rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index c3df82611..7ad3ee2b6 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -27,7 +27,7 @@ import { Networking } from '../../Network'; import { DragManager } from '../../util/DragManager'; import { SettingsManager } from '../../util/SettingsManager'; import { SnappingManager } from '../../util/SnappingManager'; -import { undoable, undoBatch } from '../../util/UndoManager'; +import { undoable, undoBatch, UndoManager } from '../../util/UndoManager'; import { CollectionFreeFormView } from '../collections/collectionFreeForm/CollectionFreeFormView'; import { ContextMenu } from '../ContextMenu'; import { ContextMenuProps } from '../ContextMenuItem'; @@ -367,7 +367,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { @action handlePromptChange = (val: string | number) => { - this._outpaintPromptInput = val; + this._outpaintPromptInput = '' + val; }; @action @@ -392,19 +392,19 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { // Set flag that outpainting is in progress this._outpaintingInProgress = true; + // Revert dimensions if prompt is blank (acts like Cancel) + if (!customPrompt) { + this.Document._width = origWidth; + this.Document._height = origHeight; + this._outpaintingInProgress = false; + return; + } + try { const currentPath = this.choosePath(field.url); const newWidth = NumCast(this.Document._width); const newHeight = NumCast(this.Document._height); - // Revert dimensions if prompt is blank (acts like Cancel) - if (!customPrompt) { - this.Document._width = origWidth; - this.Document._height = origHeight; - this._outpaintingInProgress = false; - return; - } - // Optional: add loading indicator const loadingOverlay = document.createElement('div'); loadingOverlay.style.position = 'absolute'; @@ -426,6 +426,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { newDimensions: { width: newWidth, height: newHeight }, }); + const batch = UndoManager.StartBatch('outpaint image'); if (response && typeof response === 'object' && 'url' in response && typeof response.url === 'string') { console.log('Received outpainted image:', response.url); @@ -456,6 +457,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this.Document._height = origHeight; alert('Failed to receive a valid image URL from server.'); } + batch.end(); this._mainCont?.removeChild(loadingOverlay); } catch (error) { @@ -464,7 +466,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this.Document._height = origHeight; alert('An error occurred while outpainting. Please try again.'); } finally { - this._outpaintingInProgress = false; + runInAction(() => (this._outpaintingInProgress = false)); } }; |