Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions browser_tests/fixtures/helpers/ZipTieHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ZipTieHelper {
})
}

async beginMarquee() {
async beginMarquee(withShortcut = true) {
const handle = await this.comfyPage.page.waitForFunction(() => {
const app = window.app!
const graph = app.graph
Expand Down Expand Up @@ -66,8 +66,10 @@ export class ZipTieHelper {
if (!box)
throw new Error('Workflow wires must render before the zip gesture')
await this.comfyPage.canvas.focus()
await this.comfyPage.page.keyboard.down('Meta')
await this.comfyPage.page.keyboard.down('Shift')
if (withShortcut) {
await this.comfyPage.page.keyboard.down('Meta')
await this.comfyPage.page.keyboard.down('Shift')
}
await this.comfyPage.page.mouse.move(box.from[0], box.from[1])
await this.comfyPage.page.mouse.down()
await this.comfyPage.page.mouse.move(box.to[0], box.to[1], { steps: 10 })
Expand Down
31 changes: 31 additions & 0 deletions browser_tests/tests/links/zipTie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test.describe('Zip ties', { tag: ['@canvas', '@vue-nodes'] }, () => {
test.use({
initialSettings: {
'Comfy.Canvas.NavigationMode': 'standard',
'Comfy.Graph.CanvasMenu': true,
'Comfy.Minimap.Visible': false
}
})
Expand Down Expand Up @@ -83,4 +84,34 @@ test.describe('Zip ties', { tag: ['@canvas', '@vue-nodes'] }, () => {
await expect(comfyPage.page.getByTestId('selection-rectangle')).toBeHidden()
expect(await zipTie.routing()).toEqual(initial)
})

test('the visible tool creates a tie without modifiers and Escape exits it', async ({
comfyPage,
zipTie
}) => {
const tool = comfyPage.page.getByRole('button', {
name: 'Zip tie',
exact: true
})
await expect(tool).toBeVisible()
await tool.click()
await expect(tool).toHaveAttribute('aria-pressed', 'true')

await zipTie.beginMarquee(false)
await expect(
comfyPage.page.getByTestId('selection-rectangle')
).toBeVisible()
await zipTie.finishMarquee()
await expect.poll(async () => (await zipTie.routing()).ties).toBe(1)
await expect(tool).toHaveAttribute('aria-pressed', 'false')
const created = await zipTie.routing()

await tool.click()
await zipTie.beginMarquee(false)
await zipTie.cancelMarquee()

await expect(tool).toHaveAttribute('aria-pressed', 'false')
await expect(comfyPage.page.getByTestId('selection-rectangle')).toBeHidden()
expect(await zipTie.routing()).toEqual(created)
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions docs/extensions/zip-ties.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Open `/?template=zip_tie_demo` for a model-free example with three wires already
bundled. Drag the clasp in the middle of the canvas, or right-click it to release
the tie. The example opens as a new workflow.

Click **Zip tie** in the bottom canvas toolbar, then drag a box from empty canvas
space across two or more wires. The highlighted button and crosshair cursor show
that the tool is active. Creating a tie returns to normal selection. Press
**Escape** or click **Zip tie** again to exit without creating a tie. Switching
workflows or the hand tool also exits. A box crossing fewer than two wires keeps
the tool active so you can try again.

For a one-gesture zip tie, hold **Command + Shift** on macOS or **Windows + Shift**
on Windows, then drag a box from empty canvas space across two or more wires.
Release the mouse while holding both keys to zip the crossed wires at the box's
Expand Down Expand Up @@ -40,8 +47,9 @@ pnpm test:browser:local --project=chromium browser_tests/tests/links/zipTie.spec
The tests use real keyboard and pointer input to create, move, save, reload, and
release a tie. They check the workflow saved by the backend and preserve the
original connections and earlier reroutes. A second test verifies that Escape
cancels the marquee without changing the graph. Both run in the normal E2E CI
suite, which also records a video walkthrough for newly added specs.
Both tests retain a Playwright trace on successful runs. Open the test's trace
attachment in the report to inspect screenshots, DOM snapshots, actions, network
requests, and the timeline.
cancels the marquee without changing the graph. A third test clicks the visible
tool, creates a tie without modifiers, and checks that Escape exits the tool.
All run in the normal E2E CI suite, which also records a video walkthrough for
newly added specs. The tests retain a Playwright trace on successful runs. Open
the test's trace attachment in the report to inspect screenshots, DOM snapshots,
actions, network requests, and the timeline.
2 changes: 1 addition & 1 deletion src/assets/templates/zip_tie_demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"outputs": [],
"properties": {},
"widgets_values": [
"## Try the zip tie below\nDrag the small clasp in the center to move all three wires together. Right-click the clasp and choose **Release zip tie**.\n\nTo make another tie: select two or more wires, then use the cable icon in the selection toolbar or **Zip tie selected links** in the canvas menu. No model downloads or generation needed.\n\n**Direct gesture:** hold **Cmd + Shift** on Mac or **Windows + Shift** on Windows, drag a box across two or more wires, then release the mouse to zip them. Press **Escape** to cancel."
"## Try the zip tie below\nDrag the small clasp in the center to move all three wires together. Right-click the clasp and choose **Release zip tie**.\n\nTo make another tie: click **Zip tie** in the bottom canvas toolbar, then drag a box across two or more wires. No modifier keys needed. Press **Escape** to exit the tool. No model downloads or generation needed.\n\n**Direct gesture:** hold **Cmd + Shift** on Mac or **Windows + Shift** on Windows, drag a box across two or more wires, then release the mouse to zip them. Press **Escape** to cancel."
]
}
],
Expand Down
14 changes: 14 additions & 0 deletions src/components/graph/CanvasModeSelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createI18n } from 'vue-i18n'
import CanvasModeSelector from '@/components/graph/CanvasModeSelector.vue'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useCommandStore } from '@/platform/keybindings/commandStore'
import { useZipTieToolStore } from './zipTieToolStore'

beforeEach(() => {
useCanvasStore().canvas = fromPartial({ read_only: false })
Expand Down Expand Up @@ -48,6 +49,19 @@ async function openMenu() {
}

describe('CanvasModeSelector', () => {
it.for(['Select', 'Hand'])(
'exits the zip tie tool when choosing %s',
async (mode) => {
const tool = useZipTieToolStore()
tool.toggle()
const { user } = await openMenu()

await user.click(screen.getByRole('menuitemradio', { name: mode }))

expect(tool.active).toBe(false)
}
)

it.for([
{ event: 'resize', target: window },
{ event: 'scroll', target: document }
Expand Down
2 changes: 2 additions & 0 deletions src/components/graph/CanvasModeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import {
} from '@comfyorg/design-system/lib/menu/menuStyles'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useCommandStore } from '@/platform/keybindings/commandStore'
import { useZipTieToolStore } from './zipTieToolStore'
import { cn } from '@comfyorg/tailwind-utils'

interface Props {
Expand Down Expand Up @@ -139,6 +140,7 @@ const lockCommandText = computed(() =>
)

const setMode = (mode: 'select' | 'hand') => {
useZipTieToolStore().deactivate()
if (mode === 'select' && isCanvasReadOnly.value) {
void commandStore.execute('Comfy.Canvas.Unlock')
} else if (mode === 'hand' && !isCanvasReadOnly.value) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/graph/GraphCanvasMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
:button-styles="stringifiedMinimapStyles.buttonStyles"
/>

<ZipTieToolButton
:button-styles="stringifiedMinimapStyles.buttonStyles"
/>

<div class="h-[27px] w-px self-center bg-border" />

<Button
Expand Down Expand Up @@ -114,6 +118,7 @@ import { cn } from '@comfyorg/tailwind-utils'

import CanvasModeSelector from './CanvasModeSelector.vue'
import ZoomControlsModal from './modals/ZoomControlsModal.vue'
import ZipTieToolButton from './ZipTieToolButton.vue'

const { t } = useI18n()
const commandStore = useCommandStore()
Expand Down
46 changes: 46 additions & 0 deletions src/components/graph/ZipTieToolButton.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import userEvent from '@testing-library/user-event'
import { render, screen } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'
import { createI18n } from 'vue-i18n'

import en from '@/locales/en/main.json'
import { useCommandStore } from '@/platform/keybindings/commandStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useZipTieToolStore } from './zipTieToolStore'

import ZipTieToolButton from './ZipTieToolButton.vue'

function renderButton() {
render(ZipTieToolButton, {
global: {
plugins: [createI18n({ legacy: false, locale: 'en', messages: { en } })]
}
})
}

describe('Zip tie tool button', () => {
it('shows its label and toggles the tool through its command', async () => {
const tool = useZipTieToolStore()
useCommandStore().registerCommand({
id: 'Comfy.Canvas.ToggleZipTieTool',
function: tool.toggle
})
renderButton()
const button = screen.getByRole('button', { name: 'Zip tie' })
expect(button).toHaveTextContent('Zip tie')
expect(button).toHaveAttribute('aria-pressed', 'false')

await userEvent.setup().click(button)
expect(button).toHaveAttribute('aria-pressed', 'true')

await userEvent.setup().click(button)
expect(button).toHaveAttribute('aria-pressed', 'false')
})

it('is disabled on a read-only canvas', () => {
useCanvasStore().isReadOnly = true
renderButton()

expect(screen.getByRole('button', { name: 'Zip tie' })).toBeDisabled()
})
})
31 changes: 31 additions & 0 deletions src/components/graph/ZipTieToolButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<Button
variant="secondary"
:tooltip="t('zipTie.toolHint')"
:aria-label="t('zipTie.tool')"
:aria-pressed="zipTieTool.active"
:disabled="canvasStore.isReadOnly"
:style="buttonStyles"
class="bg-transparent px-2 transition-none aria-pressed:bg-muted"
@click="commandStore.execute('Comfy.Canvas.ToggleZipTieTool')"
>
<i class="icon-[lucide--cable]" aria-hidden="true" />
<span>{{ t('zipTie.tool') }}</span>
</Button>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'

import Button from '@comfyorg/design-system/button/Button'
import { useCommandStore } from '@/platform/keybindings/commandStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useZipTieToolStore } from './zipTieToolStore'

defineProps<{ buttonStyles?: Record<string, string> }>()

const { t } = useI18n()
const commandStore = useCommandStore()
const canvasStore = useCanvasStore()
const zipTieTool = useZipTieToolStore()
</script>
16 changes: 16 additions & 0 deletions src/components/graph/zipTieToolStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useZipTieToolStore = defineStore('zipTieTool', () => {
const active = ref(false)

function toggle() {
active.value = !active.value
}

function deactivate() {
active.value = false
}

return { active, toggle, deactivate }
})
100 changes: 96 additions & 4 deletions src/extensions/core/zipTie.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import userEvent from '@testing-library/user-event'
import { screen } from '@testing-library/vue'
import { assert, describe, expect, it, onTestFinished, vi } from 'vitest'
import { nextTick } from 'vue'

import { createTestNode } from '@/lib/litegraph/src/__fixtures__/nodeHelpers'
import { LGraph } from '@/lib/litegraph/src/litegraph'
import { ContextMenu, LGraph } from '@/lib/litegraph/src/litegraph'
import { setLinkPolyline } from '@/renderer/core/canvas/linkPolylines'
import { useLinkSelectionStore } from '@/stores/linkSelectionStore'
import { useZipTieToolStore } from '@/components/graph/zipTieToolStore'
import {
createMockCanvasRenderingContext2D,
createTestCanvas
Expand Down Expand Up @@ -73,6 +75,88 @@ function setupMarquee() {
}

describe('zip tie interaction', () => {
it('creates a tie with a plain drag after activating the tool', async () => {
const { canvas, graph } = setupMarquee()
const tool = useZipTieToolStore()
const previousCursor = canvas.canvas.style.cursor
tool.toggle()
await nextTick()
expect(canvas.canvas.style.cursor).toBe('crosshair')

canvas.canvas.dispatchEvent(pointer('pointerdown', 320, 130))
canvas.canvas.dispatchEvent(pointer('pointermove', 480, 190))
expect(canvas.dragging_rectangle).not.toBeNull()
canvas.canvas.dispatchEvent(pointer('pointerup', 480, 190))
await nextTick()

expect(getZipTies(graph)).toHaveLength(1)
expect(tool.active).toBe(false)
expect(canvas.dragging_rectangle).toBeNull()
expect(canvas.canvas.style.cursor).toBe(previousCursor)
})

it('keeps the tool available when the box crosses only one wire', () => {
const { canvas, graph } = setupMarquee()
const tool = useZipTieToolStore()
tool.toggle()
canvas.canvas.dispatchEvent(pointer('pointerdown', 320, 140))
canvas.canvas.dispatchEvent(pointer('pointermove', 480, 160))
canvas.canvas.dispatchEvent(pointer('pointerup', 480, 160))

expect(getZipTies(graph)).toEqual([])
expect(tool.active).toBe(true)
})

it.for([
{
name: 'Escape',
cancel: (canvas: ReturnType<typeof createTestCanvas>) =>
canvas.canvas.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
)
},
{
name: 'changing workflows',
cancel: (canvas: ReturnType<typeof createTestCanvas>) =>
canvas.setGraph(new LGraph())
},
{
name: 'switching to the hand tool',
cancel: (canvas: ReturnType<typeof createTestCanvas>) => {
canvas.read_only = true
}
}
])('exits the tool without creating a tie on $name', async ({ cancel }) => {
const { canvas, graph } = setupMarquee()
const tool = useZipTieToolStore()
tool.toggle()
await nextTick()
canvas.canvas.dispatchEvent(pointer('pointerdown', 320, 130))
canvas.canvas.dispatchEvent(pointer('pointermove', 480, 190))

cancel(canvas)
await nextTick()
canvas.canvas.dispatchEvent(pointer('pointerup', 480, 190))

expect(tool.active).toBe(false)
expect(getZipTies(graph)).toEqual([])
expect(graph.reroutes.size).toBe(0)
expect(canvas.dragging_rectangle).toBeNull()
})

it('exits the armed tool on Escape before dragging', () => {
const { canvas, graph } = setupMarquee()
const tool = useZipTieToolStore()
tool.toggle()

canvas.canvas.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
)

expect(tool.active).toBe(false)
expect(getZipTies(graph)).toEqual([])
})

it.for([
{ from: [320, 130], to: [480, 190] },
{ from: [480, 190], to: [320, 130] }
Expand Down Expand Up @@ -191,13 +275,21 @@ describe('zip tie interaction', () => {
canvas.graph_mouse[0] = 180
canvas.graph_mouse[1] = 150
const items = zipTieExtension.getCanvasMenuItems?.(canvas)
const action = items?.[0]
assert.exists(action)
assert.exists(items)
const menu = new ContextMenu(items, {
event: pointer('pointerdown', 180, 150, 2)
})
onTestFinished(() => menu.close())
canvas.graph_mouse[0] = 800
canvas.graph_mouse[1] = 800

await action.callback?.call(document.createElement('div'))
await userEvent
.setup()
.click(screen.getByRole('menuitem', { name: 'Zip tie selected links' }))

expect(
screen.queryByRole('menuitem', { name: 'Zip tie selected links' })
).not.toBeInTheDocument()
expect(getZipTies(graph)).toHaveLength(1)
expect(
[...graph.reroutes.values()].map((reroute) => [...reroute.pos])
Expand Down
Loading
Loading