[API] LinkConnector reset no longer run after drop (#935)

`reset()` is no longer automatically called after `dropLinks`. This
brings the API in line with original intent, and how canvas is already
configured; reset is called by `pointer.finally()`.
This commit is contained in:
filtered
2025-04-18 21:45:36 +10:00
committed by GitHub
parent 5c76bec611
commit 02d165bf2a
2 changed files with 33 additions and 4 deletions

View File

@@ -211,7 +211,7 @@ export class LinkConnector {
}
}
if (renderLinks.length === 0) return this.reset()
if (renderLinks.length === 0) return
state.draggingExistingLinks = true
state.multi = true
@@ -309,11 +309,14 @@ export class LinkConnector {
* @param event Contains the drop location, in canvas space
*/
dropLinks(locator: ItemLocator, event: CanvasPointerEvent): void {
if (!this.isConnecting) return this.reset()
if (!this.isConnecting) {
console.warn("Attempted to drop links when not connecting to anything.")
return
}
const { renderLinks } = this
const mayContinue = this.events.dispatch("before-drop-links", { renderLinks, event })
if (mayContinue === false) return this.reset()
if (mayContinue === false) return
const { canvasX, canvasY } = event
const node = locator.getNodeOnPos(canvasX, canvasY) ?? undefined
@@ -331,7 +334,6 @@ export class LinkConnector {
}
this.events.dispatch("after-drop-links", { renderLinks, event })
this.reset()
}
dropOnNode(node: LGraphNode, event: CanvasPointerEvent) {

View File

@@ -208,7 +208,12 @@ describe("LinkConnector Integration", () => {
const canvasY = disconnectedNode.pos[1] + 16
const dropEvent = { canvasX, canvasY } as any
// Drop links, ensure reset has not been run
connector.dropLinks(graph, dropEvent)
expect(connector.renderLinks.length).toBe(1)
// Test reset
connector.reset()
expect(connector.renderLinks.length).toBe(0)
expect(connector.inputLinks.length).toBe(0)
@@ -239,6 +244,7 @@ describe("LinkConnector Integration", () => {
const dropEvent = { canvasX, canvasY } as any
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(connector.renderLinks.length).toBe(0)
expect(connector.inputLinks.length).toBe(0)
@@ -300,6 +306,7 @@ describe("LinkConnector Integration", () => {
connector.moveInputLink(graph, hasInputNode.inputs[0])
connector.dropLinks(graph, atOutputNodeEvent)
connector.reset()
const outputNodes = hasOutputNode.getOutputNodes(0)
expect(outputNodes).toEqual([hasInputNode, hasInputNode2])
@@ -319,6 +326,7 @@ describe("LinkConnector Integration", () => {
connector.moveInputLink(graph, hasInputNode.inputs[0])
connector.dropLinks(graph, atHasOutputNode)
connector.reset()
const outputNodes = hasOutputNode.getOutputNodes(0)
expect(outputNodes).toEqual(originalOutputNodes)
@@ -351,6 +359,7 @@ describe("LinkConnector Integration", () => {
const dropEvent = { canvasX, canvasY } as any
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(connector.renderLinks.length).toBe(0)
expect(connector.outputLinks.length).toBe(0)
@@ -395,6 +404,7 @@ describe("LinkConnector Integration", () => {
const dropEvent = { canvasX, canvasY } as any
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(connector.renderLinks.length).toBe(0)
expect(connector.outputLinks.length).toBe(0)
@@ -459,6 +469,7 @@ describe("LinkConnector Integration", () => {
connector.moveOutputLink(graph, manyOutputsNode.outputs[0])
connector.dropLinks(graph, floatingRerouteEvent)
connector.reset()
expect(manyOutputsNode.outputs[0].links).toEqual([])
expect(floatingReroute.linkIds.size).toBe(4)
@@ -489,6 +500,7 @@ describe("LinkConnector Integration", () => {
expect(connector.isRerouteValidDrop(reroute10)).toBe(false)
expect(connector.isRerouteValidDrop(reroute13)).toBe(false)
connector.dropLinks(graph, reroute7Event)
connector.reset()
const reroutesAfter = toSortedRerouteChain(manyOutputsNode.outputs[0].links!)
expect(reroutesAfter).toEqual(reroutesBefore)
@@ -507,6 +519,7 @@ describe("LinkConnector Integration", () => {
connector.moveOutputLink(graph, hasOutputNode.outputs[0])
connector.dropLinks(graph, atInputNodeEvent)
connector.reset()
expect(hasOutputNode.getOutputNodes(0)).toEqual([hasInputNode])
expect(hasInputNode.getOutputNodes(0)).toEqual([graph.getNodeById(3)])
@@ -530,6 +543,7 @@ describe("LinkConnector Integration", () => {
connector.moveOutputLink(graph, hasOutputNode.outputs[0])
connector.dropLinks(graph, atInputNodeOutSlot)
connector.reset()
expect(hasOutputNode.getOutputNodes(0)).toEqual([hasInputNode])
expect(hasInputNode.getOutputNodes(0)).toEqual([graph.getNodeById(3)])
@@ -552,6 +566,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, floatingReroute)
connector.dropLinks(graph, { canvasX, canvasY } as any)
connector.reset()
expect(graph.floatingLinks.size).toBe(0)
expect(floatingReroute.floating).toBeUndefined()
@@ -564,6 +579,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, floatingReroute)
connector.dropLinks(graph, { canvasX, canvasY } as any)
connector.reset()
expect(graph.floatingLinks.size).toBe(0)
expect(floatingReroute.floating).toBeUndefined()
@@ -585,6 +601,7 @@ describe("LinkConnector Integration", () => {
connector.moveInputLink(graph, fromFloatingInput)
const dropEvent = mockedInputDropEvent(hasInputNode, 0)
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(fromFloatingInput.link).toBeNull()
expect(fromFloatingInput._floatingLinks?.size).toBe(0)
@@ -601,6 +618,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, floatingReroute)
connector.dropLinks(graph, targetDropEvent)
connector.reset()
// Link should have been moved to the floating reroute, and no floating links should remain
expect(rerouteWithTwoLinks.floating).toBeUndefined()
@@ -613,6 +631,7 @@ describe("LinkConnector Integration", () => {
// Move the link again
connector.dragFromReroute(graph, rerouteWithTwoLinks)
connector.dropLinks(graph, targetDropEvent)
connector.reset()
// Everything should be back the way it was when we started
expect(rerouteWithTwoLinks.floating).toBeUndefined()
@@ -633,6 +652,7 @@ describe("LinkConnector Integration", () => {
const manyOutputsNode = graph.getNodeById(4)!
const dropEvent = { canvasX: manyOutputsNode.pos[0], canvasY: manyOutputsNode.pos[1] } as any
connector.dropLinks(graph, dropEvent)
connector.reset()
const output = manyOutputsNode.outputs[0]
expect(output.links!.length).toBe(6)
@@ -647,6 +667,7 @@ describe("LinkConnector Integration", () => {
dropEvent.canvasX = disconnectedNode.pos[0]
dropEvent.canvasY = disconnectedNode.pos[1]
connector.dropLinks(graph, dropEvent)
connector.reset()
const newOutput = disconnectedNode.outputs[0]
expect(newOutput.links!.length).toBe(6)
@@ -767,6 +788,7 @@ describe("LinkConnector Integration", () => {
connector.dragNewFromOutput(graph, disconnectedNode, disconnectedNode.outputs[0])
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(disconnectedNode.outputs[0].links).toEqual(nextLinkIds)
expect([...targetReroute.linkIds.values()]).toEqual(nextLinkIds)
@@ -884,6 +906,7 @@ describe("LinkConnector Integration", () => {
const dropEvent = { canvasX: toReroute.pos[0], canvasY: toReroute.pos[1] } as any
connector.dropLinks(graph, dropEvent)
connector.reset()
const newParentChain = LLink.getReroutes(graph, toReroute)
for (const rerouteId of shouldBeRemoved) {
@@ -951,6 +974,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, fromReroute)
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(listener).not.toHaveBeenCalled()
validateIntegrityNoChanges()
@@ -981,6 +1005,7 @@ describe("LinkConnector Integration", () => {
connector.dragNewFromInput(graph, node, input)
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(listener).not.toHaveBeenCalled()
validateIntegrityNoChanges()
@@ -1004,6 +1029,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, reroute)
connector.dropLinks(graph, dropEvent)
connector.reset()
expect(listener).not.toHaveBeenCalled()
validateIntegrityNoChanges()
@@ -1028,6 +1054,7 @@ describe("LinkConnector Integration", () => {
connector.dragFromReroute(graph, reroute)
connector.dropLinks(graph, dropOnInputEvent)
connector.reset()
expect(listener).not.toHaveBeenCalled()
validateIntegrityNoChanges()