Skip to content

Commit fd4ffbc

Browse files
authored
Fix render issues after moving floating input links (#841)
- Fixes floating inputs have invisible segment after moving - Fixes floating input can be moved onto existing input link, resulting in the slot having two links
1 parent 7b8f01f commit fd4ffbc

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/canvas/FloatingRenderLink.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ export class FloatingRenderLink implements RenderLink {
9696
this.fromPos = fromReroute.pos
9797
}
9898

99-
canConnectToInput(): true {
100-
return true
99+
canConnectToInput(): boolean {
100+
return this.toType === "input"
101101
}
102102

103-
canConnectToOutput(): true {
104-
return true
103+
canConnectToOutput(): boolean {
104+
return this.toType === "output"
105105
}
106106

107107
canConnectToReroute(reroute: Reroute): boolean {
@@ -118,6 +118,8 @@ export class FloatingRenderLink implements RenderLink {
118118
floatingLink.target_id = node.id
119119
floatingLink.target_slot = node.inputs.indexOf(input)
120120

121+
node.disconnectInput(node.inputs.indexOf(input))
122+
121123
this.fromSlot._floatingLinks?.delete(floatingLink)
122124
input._floatingLinks ??= new Set()
123125
input._floatingLinks.add(floatingLink)

src/canvas/LinkConnector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ export class LinkConnector {
622622

623623
for (const link of outputLinks) delete link._dragging
624624
for (const link of inputLinks) delete link._dragging
625+
for (const link of floatingLinks) delete link._dragging
625626
for (const reroute of hiddenReroutes) delete reroute._dragging
626627

627628
renderLinks.length = 0

test/LinkConnector.integration.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ describe("LinkConnector Integration", () => {
530530

531531
validateIntegrityFloatingRemoved()
532532
})
533+
534+
test("Dropping a floating input link onto input slot disconnects the existing link", ({ graph, connector }) => {
535+
const manyOutputsNode = graph.getNodeById(4)!
536+
manyOutputsNode.disconnectOutput(0)
537+
538+
const floatingInputNode = graph.getNodeById(6)!
539+
const fromFloatingInput = floatingInputNode.inputs[0]
540+
541+
const hasInputNode = graph.getNodeById(2)!
542+
const toInput = hasInputNode.inputs[0]
543+
544+
connector.moveInputLink(graph, fromFloatingInput)
545+
const dropEvent = mockedInputDropEvent(hasInputNode, 0)
546+
connector.dropLinks(graph, dropEvent)
547+
548+
expect(fromFloatingInput.link).toBeNull()
549+
expect(fromFloatingInput._floatingLinks?.size).toBe(0)
550+
551+
expect(toInput.link).toBeNull()
552+
expect(toInput._floatingLinks?.size).toBe(1)
553+
})
533554
})
534555

535556
test("Should drop floating links when both sides are disconnected", ({ graph, connector, reroutesBeforeTest, validateIntegrityNoChanges }) => {

0 commit comments

Comments
 (0)