From 67590a30038ef3a0b805f9502f690d317dfdec25 Mon Sep 17 00:00:00 2001 From: ShihChi Huang Date: Mon, 2 Nov 2026 08:17:51 +0000 Subject: [PATCH 1/3] feat: add a visible one-shot zip tie canvas tool --- .../fixtures/helpers/ZipTieHelper.ts | 8 +- browser_tests/tests/links/zipTie.spec.ts | 31 +++++ docs/extensions/zip-ties.md | 18 ++- src/assets/templates/zip_tie_demo.json | 2 +- .../graph/CanvasModeSelector.test.ts | 14 +++ src/components/graph/CanvasModeSelector.vue | 2 + src/components/graph/GraphCanvasMenu.vue | 5 + src/components/graph/ZipTieToolButton.test.ts | 46 ++++++++ src/components/graph/ZipTieToolButton.vue | 31 +++++ src/components/graph/zipTieToolStore.ts | 16 +++ src/extensions/core/zipTie.test.ts | 84 ++++++++++++++ src/extensions/core/zipTie.ts | 107 +++++++++++++++--- src/locales/en/main.json | 4 +- 13 files changed, 342 insertions(+), 26 deletions(-) create mode 100644 src/components/graph/ZipTieToolButton.test.ts create mode 100644 src/components/graph/ZipTieToolButton.vue create mode 100644 src/components/graph/zipTieToolStore.ts diff --git a/browser_tests/fixtures/helpers/ZipTieHelper.ts b/browser_tests/fixtures/helpers/ZipTieHelper.ts index 60415dbca60..d1d2a6b5ad5 100644 --- a/browser_tests/fixtures/helpers/ZipTieHelper.ts +++ b/browser_tests/fixtures/helpers/ZipTieHelper.ts @@ -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 @@ -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 }) diff --git a/browser_tests/tests/links/zipTie.spec.ts b/browser_tests/tests/links/zipTie.spec.ts index 1e7b821a03e..9a1fe46c5ee 100644 --- a/browser_tests/tests/links/zipTie.spec.ts +++ b/browser_tests/tests/links/zipTie.spec.ts @@ -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 } }) @@ -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) + }) }) diff --git a/docs/extensions/zip-ties.md b/docs/extensions/zip-ties.md index bb459f53c8f..b2b7e19faca 100644 --- a/docs/extensions/zip-ties.md +++ b/docs/extensions/zip-ties.md @@ -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 @@ -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. diff --git a/src/assets/templates/zip_tie_demo.json b/src/assets/templates/zip_tie_demo.json index 05bdd38d5d6..548a1f42411 100644 --- a/src/assets/templates/zip_tie_demo.json +++ b/src/assets/templates/zip_tie_demo.json @@ -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." ] } ], diff --git a/src/components/graph/CanvasModeSelector.test.ts b/src/components/graph/CanvasModeSelector.test.ts index 13c4b10a05b..6a92031f8f9 100644 --- a/src/components/graph/CanvasModeSelector.test.ts +++ b/src/components/graph/CanvasModeSelector.test.ts @@ -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 }) @@ -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 } diff --git a/src/components/graph/CanvasModeSelector.vue b/src/components/graph/CanvasModeSelector.vue index 7b26147eb22..7673d020f66 100644 --- a/src/components/graph/CanvasModeSelector.vue +++ b/src/components/graph/CanvasModeSelector.vue @@ -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 { @@ -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) { diff --git a/src/components/graph/GraphCanvasMenu.vue b/src/components/graph/GraphCanvasMenu.vue index 0c78bb671cc..4d75a46a6c7 100644 --- a/src/components/graph/GraphCanvasMenu.vue +++ b/src/components/graph/GraphCanvasMenu.vue @@ -24,6 +24,10 @@ :button-styles="stringifiedMinimapStyles.buttonStyles" /> + +