From e4a41669f6a638be1f9daafdab8d601d7c24fdcc Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 4 Mar 2025 07:25:10 +1100 Subject: [PATCH] Fix moving output links loses subsequent reroutes Now maintains any level of reroute chain complexity when moving links. --- src/LGraphCanvas.ts | 9 ++++++--- src/interfaces.ts | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 0ddf61844..7df8e24aa 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2246,6 +2246,7 @@ export class LGraphCanvas implements ConnectionColorContext { const otherNode = graph._nodes_by_id[link.target_id] const input = otherNode.inputs[slot] const pos = otherNode.getConnectionPos(true, slot) + const afterRerouteId = LLink.getReroutes(graph, link).at(-1)?.id const firstRerouteId = LLink.getReroutes(graph, link).at(0)?.id connectingLinks.push({ @@ -2255,7 +2256,8 @@ export class LGraphCanvas implements ConnectionColorContext { output: null, pos, direction: LinkDirection.RIGHT, - afterRerouteId: firstRerouteId, + afterRerouteId, + firstRerouteId, link, }) } @@ -4164,9 +4166,10 @@ export class LGraphCanvas implements ConnectionColorContext { : LiteGraph.CONNECTING_LINK_COLOR // If not using reroutes, link.afterRerouteId should be undefined. - const pos = link.afterRerouteId == null + const rerouteIdToConnectTo = link.firstRerouteId ?? link.afterRerouteId + const pos = rerouteIdToConnectTo == null ? link.pos - : (this.graph.reroutes.get(link.afterRerouteId)?.pos ?? link.pos) + : (this.graph.reroutes.get(rerouteIdToConnectTo)?.pos ?? link.pos) const highlightPos = this.#getHighlightPosition() // the connection being dragged by the mouse this.renderLink( diff --git a/src/interfaces.ts b/src/interfaces.ts index 86433d5ff..84cfaa1cb 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -290,6 +290,8 @@ export interface ConnectingLink extends IInputOrOutput { pos: Point direction?: LinkDirection afterRerouteId?: RerouteId + /** The first reroute on a chain */ + firstRerouteId?: RerouteId /** The link being moved, or `undefined` if creating a new link. */ link?: LLink }