From 2d50ec4a989bad417fb8d3d5048b762446ed59e8 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Sat, 13 May 2023 13:44:51 +0900 Subject: [PATCH] consider close by 'esc' key on maskeditor. --- web/extensions/core/maskeditor.js | 17 ++++++++++++++++- web/scripts/app.js | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/web/extensions/core/maskeditor.js b/web/extensions/core/maskeditor.js index f62ac19e1..6b698e2b9 100644 --- a/web/extensions/core/maskeditor.js +++ b/web/extensions/core/maskeditor.js @@ -195,7 +195,6 @@ class MaskEditorDialog extends ComfyDialog { var cancelButton = this.createRightButton("Cancel", () => { document.removeEventListener("mouseup", MaskEditorDialog.handleMouseUp); document.removeEventListener("keydown", MaskEditorDialog.handleKeyDown); - ComfyApp.onClipspaceEditorClosed(false); self.close(); }); @@ -245,6 +244,22 @@ class MaskEditorDialog extends ComfyDialog { this.setEventHandler(maskCanvas); this.is_layout_created = true; + + // replacement of onClose hook since close is not real close + const self = this; + const observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.type === 'attributes' && mutation.attributeName === 'style') { + if(self.last_style && self.last_style != 'none') + ComfyApp.onClipspaceEditorClosed(); + + self.last_style = self.element.style; + } + }); + }); + + const config = { attributes: true }; + observer.observe(this.element, config); } this.setImages(this.imgCanvas, this.backupCanvas); diff --git a/web/scripts/app.js b/web/scripts/app.js index 6f1e3ea39..86e991bd9 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -55,14 +55,17 @@ export class ComfyApp { return node.imgs || (node && node.widgets && node.widgets.findIndex(obj => obj.name === 'image') >= 0); } - static onClipspaceEditorClosed(save_mode) { + static onClipspaceEditorSave() { if(ComfyApp.clipspace_return_node) { if(save_mode) ComfyApp.pasteToClipspace(ComfyApp.clipspace_return_node); - ComfyApp.clipspace_return_node = null; } } + static onClipspaceEditorClosed() { + ComfyApp.clipspace_return_node = null; + } + static copyToClipspace(node) { var widgets = null; if(node.widgets) {