Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ test.describe('Vue Node Link Interaction', () => {
0,
false
)
const dropPos = { x: outputCenter.x + 200, y: outputCenter.y - 120 }
const dropPos = { x: outputCenter.x + 200, y: outputCenter.y - 100 }

await comfyMouse.move(outputCenter)
await comfyPage.page.keyboard.down('Shift')
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/extensions/vueNodes/components/InputSlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
ref="connectionDotRef"
:color="slotColor"
:class="cn('-translate-x-1/2 w-3', errorClassesDot)"
@click="onClick"
@dblclick="onDoubleClick"
@pointerdown="onPointerDown"
/>

Expand Down Expand Up @@ -142,7 +144,7 @@ useSlotElementTracking({
element: slotElRef
})

const { onPointerDown } = useSlotLinkInteraction({
const { onClick, onDoubleClick, onPointerDown } = useSlotLinkInteraction({
nodeId: props.nodeId ?? '',
index: props.index,
type: 'input'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tryOnScopeDispose, useEventListener } from '@vueuse/core'
import type { Fn } from '@vueuse/core'

import { useSharedCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import type { LGraph } from '@/lib/litegraph/src/LGraph'
import type { LGraphNode, NodeId } from '@/lib/litegraph/src/LGraphNode'
import { LLink } from '@/lib/litegraph/src/LLink'
Expand Down Expand Up @@ -29,6 +30,7 @@ import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
import type { Point } from '@/renderer/core/layout/types'
import { toPoint } from '@/renderer/core/layout/utils/geometry'
import { createSlotLinkDragContext } from '@/renderer/extensions/vueNodes/composables/slotLinkDragContext'
import { augmentToCanvasPointerEvent } from '@/renderer/extensions/vueNodes/utils/eventUtils'
import { app } from '@/scripts/app'
import { createRafBatch } from '@/utils/rafBatch'

Expand All @@ -39,6 +41,8 @@ interface SlotInteractionOptions {
}

interface SlotInteractionHandlers {
onClick: (event: PointerEvent) => void
onDoubleClick: (event: PointerEvent) => void
onPointerDown: (event: PointerEvent) => void
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Expand Down Expand Up @@ -500,7 +504,7 @@ export function useSlotLinkInteraction({

const hasConnected = connectByPriority(canvasEvent.target, snappedCandidate)

if (!hasConnected) {
if (!hasConnected && event.target === app.canvas?.canvas) {
activeAdapter?.dropOnCanvas(canvasEvent)
}

Expand Down Expand Up @@ -716,7 +720,28 @@ export function useSlotLinkInteraction({
}
})

function onDoubleClick(e: PointerEvent) {
const canvas = useCanvasStore().getCanvas()
const { graph } = canvas
if (!graph) return
const node = graph.getNodeById(nodeId)
if (!node) return
augmentToCanvasPointerEvent(e, node, app.canvas)
node.onInputDblClick?.(index, e)
}
function onClick(e: PointerEvent) {
const canvas = useCanvasStore().getCanvas()
const { graph } = canvas
if (!graph) return
const node = graph.getNodeById(nodeId)
if (!node) return
augmentToCanvasPointerEvent(e, node, app.canvas)
node.onInputClick?.(index, e)
}
Comment on lines +722 to +737

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For later (probably)
The common parts here could definitely be extracted and unified.

Question: Is there a reason we get the canvas from the canvasStore in one place but use app.canvas in another?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the rabbit noticed too 🐇

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. From testing, app.canvas was undefined here.

Wasn't able to find a satifactory answer for "why" though. The app reference here had app.vueAppReady = False which leads me to believe the function was somehow getting a stale reference.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you replace app.canvas with canvas?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tragic Cannot find name 'canvas'.

I'm no longer able to reproduce the earlier issues with app.canvas being undefined and the distinction seems moot when the event augmentation is using app.canvas without difficulty. Pushing a commit to swap off and see if anything screams.


return {
onClick,
onDoubleClick,
onPointerDown
}
}
13 changes: 13 additions & 0 deletions src/renderer/extensions/vueNodes/utils/eventUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas'
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events'

export function augmentToCanvasPointerEvent(
e: PointerEvent,
node: LGraphNode,
canvas: LGraphCanvas
): asserts e is CanvasPointerEvent {
canvas.adjustMouseEvent(e)
canvas.graph_mouse[0] = e.offsetX + node.pos[0]
canvas.graph_mouse[1] = e.offsetY + node.pos[1]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { useChainCallback } from '@/composables/functional/useChainCallback'
import { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer'
import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas'
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { augmentToCanvasPointerEvent } from '@/renderer/extensions/vueNodes/utils/eventUtils'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
import type { SimplifiedWidget } from '@/types/simplifiedWidget'

Expand Down Expand Up @@ -64,16 +64,10 @@ function draw() {
ctx.scale(scaleFactor, scaleFactor)
widgetInstance.draw?.(ctx, node, width, 1, height)
}
function translateEvent(e: PointerEvent): asserts e is CanvasPointerEvent {
if (!node) return
canvas.adjustMouseEvent(e)
canvas.graph_mouse[0] = e.offsetX + node.pos[0]
canvas.graph_mouse[1] = e.offsetY + node.pos[1]
}
//See LGraphCanvas.processWidgetClick
function handleDown(e: PointerEvent) {
if (!node || !widgetInstance || !pointer) return
translateEvent(e)
augmentToCanvasPointerEvent(e, node, canvas)
pointer.down(e)
if (widgetInstance.mouse)
pointer.onDrag = (e) =>
Expand All @@ -82,14 +76,14 @@ function handleDown(e: PointerEvent) {
canvas.processWidgetClick(e, node, widgetInstance, pointer)
}
function handleUp(e: PointerEvent) {
if (!pointer) return
translateEvent(e)
if (!pointer || !node) return
augmentToCanvasPointerEvent(e, node, canvas)
e.click_time = e.timeStamp - (pointer?.eDown?.timeStamp ?? 0)
pointer.up(e)
}
function handleMove(e: PointerEvent) {
if (!pointer) return
translateEvent(e)
if (!pointer || !node) return
augmentToCanvasPointerEvent(e, node, canvas)
pointer.move(e)
}
</script>
Expand Down
Loading