mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 20:50:06 +00:00
[API] Add dirty state flag for selectedItems (#1050)
This commit is contained in:
@@ -827,6 +827,8 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
remove(node: LGraphNode | LGraphGroup): void {
|
||||
// LEGACY: This was changed from constructor === LiteGraph.LGraphGroup
|
||||
if (node instanceof LGraphGroup) {
|
||||
this.canvasAction(c => 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<Serialisabl
|
||||
for (const canvas of list_of_graphcanvas) {
|
||||
if (canvas.selected_nodes[node.id])
|
||||
delete canvas.selected_nodes[node.id]
|
||||
|
||||
canvas.deselect(node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1290,6 +1294,8 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
const reroute = reroutes.get(id)
|
||||
if (!reroute) return
|
||||
|
||||
this.canvasAction(c => c.deselect(reroute))
|
||||
|
||||
// Extract reroute from the reroute chain
|
||||
const { parentId, linkIds, floatingLinkIds } = reroute
|
||||
for (const reroute of reroutes.values()) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user