* Removes a reroute from the graph * @param id ID of reroute to remove
(id: RerouteId)
| 1322 | * @param id ID of reroute to remove |
| 1323 | */ |
| 1324 | removeReroute(id: RerouteId): void { |
| 1325 | const { reroutes } = this |
| 1326 | const reroute = reroutes.get(id) |
| 1327 | if (!reroute) return |
| 1328 | |
| 1329 | this.canvasAction(c => c.deselect(reroute)) |
| 1330 | |
| 1331 | // Extract reroute from the reroute chain |
| 1332 | const { parentId, linkIds, floatingLinkIds } = reroute |
| 1333 | for (const reroute of reroutes.values()) { |
| 1334 | if (reroute.parentId === id) reroute.parentId = parentId |
| 1335 | } |
| 1336 | |
| 1337 | for (const linkId of linkIds) { |
| 1338 | const link = this._links.get(linkId) |
| 1339 | if (link && link.parentId === id) link.parentId = parentId |
| 1340 | } |
| 1341 | |
| 1342 | for (const linkId of floatingLinkIds) { |
| 1343 | const link = this.floatingLinks.get(linkId) |
| 1344 | if (!link) { |
| 1345 | console.warn(`Removed reroute had floating link ID that did not exist [${linkId}]`) |
| 1346 | continue |
| 1347 | } |
| 1348 | |
| 1349 | // A floating link is a unique branch; if there is no parent reroute, or |
| 1350 | // the parent reroute has any other links, remove this floating link. |
| 1351 | const floatingReroutes = LLink.getReroutes(this, link) |
| 1352 | const lastReroute = floatingReroutes.at(-1) |
| 1353 | const secondLastReroute = floatingReroutes.at(-2) |
| 1354 | |
| 1355 | if (reroute !== lastReroute) { |
| 1356 | continue |
| 1357 | } else if (secondLastReroute?.totalLinks !== 1) { |
| 1358 | this.removeFloatingLink(link) |
| 1359 | } else if (link.parentId === id) { |
| 1360 | link.parentId = parentId |
| 1361 | secondLastReroute.floating = reroute.floating |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | reroutes.delete(id) |
| 1366 | // This does not belong here; it should be handled by the caller, or run by a remove-many API. |
| 1367 | // https://github.com/Comfy-Org/litegraph.js/issues/898 |
| 1368 | this.setDirtyCanvas(false, true) |
| 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * Destroys a link |
no test coverage detected