Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
40 changes: 26 additions & 14 deletions browser_tests/tests/vueNodes/interactions/canvas/pan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,22 @@ test.describe('Vue Nodes Canvas Pan', { tag: '@vue-nodes' }, () => {
}
)

test.describe('spacebar panning', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.settings.setSetting(
'Comfy.Canvas.NavigationMode',
'standard'
)
await comfyPage.workflow.loadWorkflow('vueNodes/simple-triple')
})
test('spacebar panning', async ({ comfyPage, comfyMouse }) => {
await comfyPage.settings.setSetting(
'Comfy.Canvas.NavigationMode',
'standard'
)
await comfyPage.workflow.loadWorkflow('vueNodes/simple-triple')
const node = await comfyPage.vueNodes.getFixtureByTitle('KSampler')

test('Space + left-drag on a Vue node pans canvas', async ({
comfyPage,
comfyMouse
}) => {
const node = comfyPage.vueNodes.getNodeByTitle('KSampler')
await test.step('Space + click on a node starts a pan', async () => {
const offsetBefore = await comfyPage.canvasOps.getOffset()

await comfyPage.canvas.focus()
await comfyPage.page.keyboard.down('Space')
await expect.poll(() => comfyPage.canvasOps.isReadOnly()).toBe(true)
try {
await comfyMouse.dragElementBy(node, { x: 140, y: 90 })
await comfyMouse.dragElementBy(node.root, { x: -300, y: 0 })
} finally {
await comfyPage.page.keyboard.up('Space')
}
Expand All @@ -56,6 +51,23 @@ test.describe('Vue Nodes Canvas Pan', { tag: '@vue-nodes' }, () => {
.poll(() => comfyPage.canvasOps.getOffset())
.not.toEqual(offsetBefore)
})

await test.step('while dragging node, spacebar starts pan', async () => {

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.

This seems like several steps...

await node.header.hover()
const offset1 = await comfyPage.canvasOps.getOffset()
await comfyPage.page.mouse.down()
await comfyPage.page.mouse.move(500, 500, { steps: 5 })
expect(await comfyPage.canvasOps.getOffset()).toEqual(offset1)
await comfyPage.page.keyboard.down('Space')
await comfyPage.page.mouse.move(400, 400, { steps: 5 })
await expect
.poll(() => comfyPage.canvasOps.getOffset())
.not.toEqual(offset1)
await comfyPage.page.keyboard.up('Space')
const offset2 = await comfyPage.canvasOps.getOffset()
await comfyPage.page.mouse.move(500, 500, { steps: 5 })
expect(await comfyPage.canvasOps.getOffset()).toEqual(offset2)
})
Comment thread
AustinMroz marked this conversation as resolved.
Outdated
})

test(
Expand Down
1 change: 1 addition & 0 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
@pointerdown.capture="forwardPointerDownPanEvent"
@pointerup.capture="forwardPointerUpPanEvent"
@pointermove.capture="forwardPointerMovePanEvent"
@keydown.space="canvasInteractions.forwardEventToCanvas"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
>
<!-- Vue nodes rendered based on graph nodes -->
<LGraphNode
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/extensions/vueNodes/layout/useNodeDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ function useNodeDragIndividual() {
if (!dragStartPos || !dragStartMouse) {
return
}
if (canvasStore.isReadOnly) {
const canvas = canvasStore.getCanvas()
const delta = [event.clientX - lastPointerX, event.clientY - lastPointerY]

canvas.ds.offset[0] += delta[0] / canvas.ds.scale
canvas.ds.offset[1] += delta[1] / canvas.ds.scale
canvas.setDirty(true, true)
lastPointerX = event.clientX
lastPointerY = event.clientY
dragStartMouse.x += delta[0]
dragStartMouse.y += delta[1]
Comment on lines +204 to +210

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.

The fact that we have to update this many things at once is a pretty big code smell, IMO.
(Not for this PR, just whining)

return
Comment thread
AustinMroz marked this conversation as resolved.
}

// Throttle position updates using requestAnimationFrame for better performance
if (rafId !== null) return // Skip if frame already scheduled
Expand Down
Loading