Skip to content

Commit 5e6a759

Browse files
committed
fix mask editor bug under vueNodes
1 parent 338cbd4 commit 5e6a759

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/renderer/extensions/vueNodes/components/ImagePreview.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import { computed, ref, watch } from 'vue'
122122
import { useI18n } from 'vue-i18n'
123123
124124
import { downloadFile } from '@/base/common/downloadUtil'
125+
import { app } from '@/scripts/app'
125126
import { useCommandStore } from '@/stores/commandStore'
126127
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
127128
@@ -186,8 +187,29 @@ const handleImageError = () => {
186187
actualDimensions.value = null
187188
}
188189
189-
const handleEditMask = () => {
190-
void commandStore.execute('Comfy.MaskEditor.OpenMaskEditor')
190+
const handleEditMask = async () => {
191+
if (props.nodeId) {
192+
const node = app.rootGraph?.getNodeById(props.nodeId)
193+
if (node) {
194+
node.imageIndex = currentIndex.value
195+
196+
node.imgs = await Promise.all(
197+
props.imageUrls.map((url) => {
198+
return new Promise<HTMLImageElement>((resolve) => {
199+
const img = new Image()
200+
201+
img.onload = () => resolve(img)
202+
203+
img.src = url
204+
})
205+
})
206+
)
207+
208+
app.canvas?.selectNode(node)
209+
}
210+
}
211+
212+
await commandStore.execute('Comfy.MaskEditor.OpenMaskEditor')
191213
}
192214
193215
const handleDownload = () => {

src/scripts/app.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,19 @@ export class ComfyApp {
379379
const paintedIndex = selectedIndex + 1
380380
const combinedIndex = selectedIndex + 2
381381

382+
// for vueNodes mode
383+
let images = node.images
384+
if (!images) {
385+
const outputs = useNodeOutputStore().getNodeOutputs(node)
386+
387+
images = outputs?.images
388+
}
389+
382390
ComfyApp.clipspace = {
383391
widgets: widgets,
384392
imgs: imgs,
385393
original_imgs: orig_imgs,
386-
images: node.images,
394+
images: images,
387395
selectedIndex: selectedIndex,
388396
img_paste_mode: 'selected', // reset to default im_paste_mode state on copy action
389397
paintedIndex: paintedIndex,
@@ -410,7 +418,8 @@ export class ComfyApp {
410418
ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src
411419
}
412420
if (ComfyApp.clipspace.imgs && node.imgs) {
413-
if (node.images && ComfyApp.clipspace.images) {
421+
// Update node.images even if it's initially undefined (vueNodes mode)
422+
if (ComfyApp.clipspace.images) {
414423
if (ComfyApp.clipspace['img_paste_mode'] == 'selected') {
415424
node.images = [
416425
ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']]
@@ -512,6 +521,13 @@ export class ComfyApp {
512521
}
513522

514523
app.graph.setDirtyCanvas(true)
524+
525+
if (node.images && app.nodeOutputs[node.id]) {
526+
useNodeOutputStore().nodeOutputs[node.id] = {
527+
...app.nodeOutputs[node.id],
528+
images: node.images
529+
}
530+
}
515531
}
516532
}
517533

0 commit comments

Comments
 (0)