[API] Add dirty state flag for selectedItems (#1050)

This commit is contained in:
filtered
2025-05-15 19:33:51 +10:00
committed by GitHub
parent ad528461c9
commit 19b7d28d97
2 changed files with 19 additions and 0 deletions

View File

@@ -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()