From 19b7d28d97581acbe64b122509fc0a7e7e3fc5f1 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Thu, 15 May 2025 19:33:51 +1000 Subject: [PATCH] [API] Add dirty state flag for selectedItems (#1050) --- src/LGraph.ts | 6 ++++++ src/LGraphCanvas.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/LGraph.ts b/src/LGraph.ts index 69ef05ffe7..dbab013bca 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -827,6 +827,8 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable c.deselect(node)) + const index = this._groups.indexOf(node) if (index != -1) { this._groups.splice(index, 1) @@ -887,6 +889,8 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable c.deselect(reroute)) + // Extract reroute from the reroute chain const { parentId, linkIds, floatingLinkIds } = reroute for (const reroute of reroutes.values()) { diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 6555a906c1..25c1898845 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -162,6 +162,12 @@ export interface LGraphCanvasState { hoveringOver: CanvasItem /** If `true`, pointer move events will set the canvas cursor style. */ shouldSetCursor: boolean + + /** + * Dirty flag indicating that {@link selectedItems} has changed. + * Downstream consumers may reset to false once actioned. + */ + selectionChanged: boolean } /** @@ -257,6 +263,7 @@ export class LGraphCanvas { readOnly: false, hoveringOver: CanvasItem.Nothing, shouldSetCursor: true, + selectionChanged: false, } declare subgraph?: Subgraph @@ -1538,6 +1545,7 @@ export class LGraphCanvas { this.selected_nodes = {} this.selected_group = null this.selectedItems.clear() + this.state.selectionChanged = true this.onSelectionChange?.(this.selected_nodes) this.visible_nodes = [] @@ -3443,6 +3451,7 @@ export class LGraphCanvas { item.selected = true this.selectedItems.add(item) + this.state.selectionChanged = true if (!(item instanceof LGraphNode)) return // Node-specific handling @@ -3475,6 +3484,7 @@ export class LGraphCanvas { item.selected = false this.selectedItems.delete(item) + this.state.selectionChanged = true if (!(item instanceof LGraphNode)) return // Node-specific handling @@ -3613,6 +3623,7 @@ export class LGraphCanvas { } } + this.state.selectionChanged = true this.onSelectionChange?.(this.selected_nodes) } @@ -3650,6 +3661,8 @@ export class LGraphCanvas { this.selectedItems.clear() this.current_node = null this.highlighted_links = {} + + this.state.selectionChanged = true this.onSelectionChange?.(this.selected_nodes) this.setDirty(true) graph.afterChange()