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 }) => {