Skip to content

Commit f2f8805

Browse files
committed
fix mask editor bug under vueNodes
1 parent c9da8b2 commit f2f8805

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
@error="handleImageError"
4444
/>
4545

46+
<!-- Hidden preloaded images for mask editor -->
47+
<img
48+
v-for="(url, i) in imageUrls"
49+
v-show="false"
50+
:key="i"
51+
ref="imageEls"
52+
:src="url"
53+
alt=""
54+
/>
55+
4656
<!-- Floating Action Buttons (appear on hover) -->
4757
<div v-if="isHovered" class="actions absolute top-2 right-2 flex gap-1">
4858
<!-- Mask/Edit Button -->
@@ -122,6 +132,7 @@ import { computed, ref, watch } from 'vue'
122132
import { useI18n } from 'vue-i18n'
123133
124134
import { downloadFile } from '@/base/common/downloadUtil'
135+
import { app } from '@/scripts/app'
125136
import { useCommandStore } from '@/stores/commandStore'
126137
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
127138
@@ -147,6 +158,8 @@ const actualDimensions = ref<string | null>(null)
147158
const imageError = ref(false)
148159
const isLoading = ref(false)
149160
161+
const imageEls = ref<HTMLImageElement[]>([])
162+
150163
// Computed values
151164
const currentImageUrl = computed(() => props.imageUrls[currentIndex.value])
152165
const hasMultipleImages = computed(() => props.imageUrls.length > 1)
@@ -187,6 +200,13 @@ const handleImageError = () => {
187200
}
188201
189202
const handleEditMask = () => {
203+
if (!props.nodeId) return
204+
const node = app.rootGraph?.getNodeById(props.nodeId)
205+
if (!node) return
206+
node.imageIndex = currentIndex.value
207+
node.imgs = imageEls.value
208+
app.canvas?.select(node)
209+
190210
void commandStore.execute('Comfy.MaskEditor.OpenMaskEditor')
191211
}
192212

src/scripts/app.ts

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

382+
// for vueNodes mode
383+
const images =
384+
node.images ?? useNodeOutputStore().getNodeOutputs(node)?.images
385+
382386
ComfyApp.clipspace = {
383387
widgets: widgets,
384388
imgs: imgs,
385389
original_imgs: orig_imgs,
386-
images: node.images,
390+
images: images,
387391
selectedIndex: selectedIndex,
388392
img_paste_mode: 'selected', // reset to default im_paste_mode state on copy action
389393
paintedIndex: paintedIndex,
@@ -410,7 +414,8 @@ export class ComfyApp {
410414
ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src
411415
}
412416
if (ComfyApp.clipspace.imgs && node.imgs) {
413-
if (node.images && ComfyApp.clipspace.images) {
417+
// Update node.images even if it's initially undefined (vueNodes mode)
418+
if (ComfyApp.clipspace.images) {
414419
if (ComfyApp.clipspace['img_paste_mode'] == 'selected') {
415420
node.images = [
416421
ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']]
@@ -512,6 +517,13 @@ export class ComfyApp {
512517
}
513518

514519
app.graph.setDirtyCanvas(true)
520+
521+
if (node.images && app.nodeOutputs[node.id]) {
522+
useNodeOutputStore().nodeOutputs[node.id] = {
523+
...app.nodeOutputs[node.id],
524+
images: node.images
525+
}
526+
}
515527
}
516528
}
517529

0 commit comments

Comments
 (0)