Skip to content
Open
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
50 changes: 50 additions & 0 deletions browser_tests/tests/links/linkVisibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,56 @@ test.describe(
)
})
})

test('double-clicking a stack renames every link in it', async ({
comfyPage,
linkVisibility
}) => {
const undoSizeBeforeRename =
(await comfyPage.workflow.getUndoQueueSize()) ?? 0
const exportedLinkPresentations = async () =>
Object.values(
(await comfyPage.workflow.getExportedWorkflow()).extra
?.linkPresentation ?? {}
)

await test.step('Name the unlabelled stack', async () => {
await linkVisibility.openRenamePromptAtOutputBadgeRow(
checkpointLoaderId,
clipSlot,
0
)
await expect(linkVisibility.promptInput).toHaveValue('')
await comfyPage.nodeOps.fillLegacyWidgetDialog('enc')
await expect(linkVisibility.promptInput).toBeHidden()
await expect.poll(exportedLinkPresentations).toEqual([
{ hidden: true, label: 'enc' },
{ hidden: true, label: 'enc' }
])
})

await test.step('The links stay one collapsed stack with the new name', async () => {
await linkVisibility.parkPointer()
await expectRegionScreenshot(
comfyPage.page,
[
await comfyPage.nodeOps.getNodeRefById(checkpointLoaderId),
...(await comfyPage.nodeOps.getNodeRefsByType('CLIPTextEncode'))
],
'link-stack-same-name-collapsed.png'
)
})

await test.step('One undo removes the name from every link', async () => {
await expect
.poll(() => comfyPage.workflow.getUndoQueueSize())
.toBe(undoSizeBeforeRename + 1)
await comfyPage.keyboard.undo()
await expect
.poll(exportedLinkPresentations)
.toEqual([{ hidden: true }, { hidden: true }])
})
})
}
)

Expand Down
37 changes: 30 additions & 7 deletions src/composables/graph/useGroupContextMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest'

import { useSelectedLiteGraphItems } from '@/composables/canvas/useSelectedLiteGraphItems'
import { useGroupContextMenu } from '@/composables/graph/useGroupContextMenu'
import type { CanvasPointerEvent } from '@/lib/litegraph/src/litegraph'
import type { getCanvasContextMenuTarget } from '@/lib/litegraph/src/canvas/getCanvasContextMenuTarget'
import type { CanvasPointerEvent, Reroute } from '@/lib/litegraph/src/litegraph'
import {
LGraph,
LGraphCanvas,
Expand All @@ -18,21 +19,24 @@ import {
createMockCanvasRenderingContext2D,
createTestCanvas
} from '@/utils/__tests__/canvasTestUtils'
import { createMockLLink } from '@/utils/__tests__/litegraphTestUtils'
import { toLinkId } from '@comfyorg/graph-model/linkId'
import { toRerouteId } from '@comfyorg/graph-model/rerouteId'

const { mockShowNodeOptions, mockGetCanvasContextMenuTarget } = vi.hoisted(
() => ({
mockShowNodeOptions: vi.fn(),
mockGetCanvasContextMenuTarget: vi.fn<
() => { reroute?: unknown; link?: unknown; group?: unknown }
>(() => ({}))
mockGetCanvasContextMenuTarget: vi.fn<typeof getCanvasContextMenuTarget>(
() => ({})
)
})
)

vi.mock(import('@/composables/graph/useMoreOptionsMenu'), () => ({
showNodeOptions: mockShowNodeOptions
}))

vi.mock<unknown>(
vi.mock(
import('@/lib/litegraph/src/canvas/getCanvasContextMenuTarget'),
() => ({
getCanvasContextMenuTarget: mockGetCanvasContextMenuTarget
Expand Down Expand Up @@ -241,7 +245,26 @@ describe('useGroupContextMenu', () => {

it('falls through to the legacy menu when the cursor is on a reroute', () => {
mockGetCanvasContextMenuTarget.mockReturnValue({
reroute: { id: 5 },
reroute: fromPartial<Reroute>({ id: toRerouteId(5) }),
group
})

invoke(undefined)

expect(legacyMenuMock).toHaveBeenCalledOnce()
expect(mockShowNodeOptions).not.toHaveBeenCalled()
expect(stubCanvas.selectedItems.size).toBe(0)
})

it('falls through to the legacy menu when the cursor is on a stack of hidden links', () => {
mockGetCanvasContextMenuTarget.mockReturnValue({
stack: {
stackKey: 'output:1:0',
links: [
createMockLLink({ id: toLinkId(5) }),
createMockLLink({ id: toLinkId(6) })
]
},
group
})

Expand All @@ -254,7 +277,7 @@ describe('useGroupContextMenu', () => {

it('falls through to the legacy menu when the cursor is on a link', () => {
mockGetCanvasContextMenuTarget.mockReturnValue({
link: { id: 5 },
link: createMockLLink({ id: toLinkId(5) }),
group
})

Expand Down
17 changes: 11 additions & 6 deletions src/composables/graph/useGroupContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ function shouldUseLegacyContextMenu(
return Boolean(node) || !LiteGraph.vueNodesMode || !canvas.graph
}

function groupUnderBareCursor(canvas: LGraphCanvas, x: number, y: number) {
const { reroute, link, stack, group } = getCanvasContextMenuTarget(
canvas,
x,
y
)
return reroute || link || stack ? undefined : group
}

/**
* Routes Nodes 2.0 group right-clicks to Vue while nodes, reroutes,
* background, and legacy mode stay on litegraph.
Expand All @@ -31,12 +40,8 @@ export function useGroupContextMenu() {
return
}

const { reroute, link, group } = getCanvasContextMenuTarget(
this,
event.canvasX,
event.canvasY
)
if (reroute || link || !group) {
const group = groupUnderBareCursor(this, event.canvasX, event.canvasY)
if (!group) {
original.apply(this, args)
return
}
Expand Down
11 changes: 10 additions & 1 deletion src/lib/litegraph/src/CanvasPointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type {
GesturePolicy,
GestureState
} from './canvas/reduceGesture'
import { idleGesture, reduceGesture } from './canvas/reduceGesture'
import {
doubleClickedClick,
idleGesture,
reduceGesture
} from './canvas/reduceGesture'
import type { CompassCorners } from '@comfyorg/shared-frontend-utils/geometry'
import type { CanvasPointerEvent } from '@comfyorg/graph-model/events'

Expand Down Expand Up @@ -67,6 +71,11 @@ export class CanvasPointer {
return this.state.phase === 'dragging'
}

/** The `timeStamp` of the press that the current press double-clicks, if any. */
get doubleClickedTimeStamp(): number | undefined {
return doubleClickedClick(this.state)?.timeStamp
}

private state: GestureState = idleGesture
private releaseCapture?: () => void

Expand Down
Loading
Loading