From a20bae064f9bc9053f15a7dc83a718055291b3b3 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 28 Mar 2025 05:18:22 +1100 Subject: [PATCH] Allow floating reroute switches (#862) - Resolves https://github.com/Comfy-Org/ComfyUI_frontend/issues/3247 Bypasses the logic that automatically removed reroutes that had no remaining links. Reroutes are now always converted to floating whenever reroutes are reconnected. --- src/canvas/ToInputRenderLink.ts | 2 ++ test/LinkConnector.integration.test.ts | 32 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/canvas/ToInputRenderLink.ts b/src/canvas/ToInputRenderLink.ts index 8b1d285887..78a5363dd7 100644 --- a/src/canvas/ToInputRenderLink.ts +++ b/src/canvas/ToInputRenderLink.ts @@ -65,6 +65,8 @@ export class ToInputRenderLink implements RenderLink { // Set the parentId of the reroute we dropped on, to the reroute we dragged from reroute.parentId = fromReroute?.id + // Keep reroutes when disconnecting the original link + existingLink.disconnect(this.network, "output") const newLink = outputNode.connectSlots(fromSlot, inputNode, input, existingLink.parentId) // Connecting from the final reroute of a floating reroute chain diff --git a/test/LinkConnector.integration.test.ts b/test/LinkConnector.integration.test.ts index 404016e2e7..594a6ad0e7 100644 --- a/test/LinkConnector.integration.test.ts +++ b/test/LinkConnector.integration.test.ts @@ -551,6 +551,38 @@ describe("LinkConnector Integration", () => { expect(toInput.link).toBeNull() expect(toInput._floatingLinks?.size).toBe(1) }) + + test("Allow reroutes to be used as manual switches", ({ graph, connector, floatingReroute, validateIntegrityNoChanges }) => { + const rerouteWithTwoLinks = graph.reroutes.get(3)! + const targetNode = graph.getNodeById(2)! + + const targetDropEvent = mockedInputDropEvent(targetNode, 0) + + connector.dragFromReroute(graph, floatingReroute) + connector.dropLinks(graph, targetDropEvent) + + // Link should have been moved to the floating reroute, and no floating links should remain + expect(rerouteWithTwoLinks.floating).toBeUndefined() + expect(floatingReroute.floating).toBeUndefined() + expect(rerouteWithTwoLinks.floatingLinkIds.size).toBe(0) + expect(floatingReroute.floatingLinkIds.size).toBe(0) + expect(rerouteWithTwoLinks.linkIds.size).toBe(1) + expect(floatingReroute.linkIds.size).toBe(1) + + // Move the link again + connector.dragFromReroute(graph, rerouteWithTwoLinks) + connector.dropLinks(graph, targetDropEvent) + + // Everything should be back the way it was when we started + expect(rerouteWithTwoLinks.floating).toBeUndefined() + expect(floatingReroute.floating).toEqual({ slotType: "output" }) + expect(rerouteWithTwoLinks.floatingLinkIds.size).toBe(0) + expect(floatingReroute.floatingLinkIds.size).toBe(1) + expect(rerouteWithTwoLinks.linkIds.size).toBe(2) + expect(floatingReroute.linkIds.size).toBe(0) + + validateIntegrityNoChanges() + }) }) test("Should drop floating links when both sides are disconnected", ({ graph, connector, reroutesBeforeTest, validateIntegrityNoChanges }) => {