mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 19:21:54 +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 {
|
remove(node: LGraphNode | LGraphGroup): void {
|
||||||
// LEGACY: This was changed from constructor === LiteGraph.LGraphGroup
|
// LEGACY: This was changed from constructor === LiteGraph.LGraphGroup
|
||||||
if (node instanceof LGraphGroup) {
|
if (node instanceof LGraphGroup) {
|
||||||
|
this.canvasAction(c => c.deselect(node))
|
||||||
|
|
||||||
const index = this._groups.indexOf(node)
|
const index = this._groups.indexOf(node)
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
this._groups.splice(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) {
|
for (const canvas of list_of_graphcanvas) {
|
||||||
if (canvas.selected_nodes[node.id])
|
if (canvas.selected_nodes[node.id])
|
||||||
delete 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)
|
const reroute = reroutes.get(id)
|
||||||
if (!reroute) return
|
if (!reroute) return
|
||||||
|
|
||||||
|
this.canvasAction(c => c.deselect(reroute))
|
||||||
|
|
||||||
// Extract reroute from the reroute chain
|
// Extract reroute from the reroute chain
|
||||||
const { parentId, linkIds, floatingLinkIds } = reroute
|
const { parentId, linkIds, floatingLinkIds } = reroute
|
||||||
for (const reroute of reroutes.values()) {
|
for (const reroute of reroutes.values()) {
|
||||||
|
|||||||
@@ -162,6 +162,12 @@ export interface LGraphCanvasState {
|
|||||||
hoveringOver: CanvasItem
|
hoveringOver: CanvasItem
|
||||||
/** If `true`, pointer move events will set the canvas cursor style. */
|
/** If `true`, pointer move events will set the canvas cursor style. */
|
||||||
shouldSetCursor: boolean
|
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,
|
readOnly: false,
|
||||||
hoveringOver: CanvasItem.Nothing,
|
hoveringOver: CanvasItem.Nothing,
|
||||||
shouldSetCursor: true,
|
shouldSetCursor: true,
|
||||||
|
selectionChanged: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
declare subgraph?: Subgraph
|
declare subgraph?: Subgraph
|
||||||
@@ -1538,6 +1545,7 @@ export class LGraphCanvas {
|
|||||||
this.selected_nodes = {}
|
this.selected_nodes = {}
|
||||||
this.selected_group = null
|
this.selected_group = null
|
||||||
this.selectedItems.clear()
|
this.selectedItems.clear()
|
||||||
|
this.state.selectionChanged = true
|
||||||
this.onSelectionChange?.(this.selected_nodes)
|
this.onSelectionChange?.(this.selected_nodes)
|
||||||
|
|
||||||
this.visible_nodes = []
|
this.visible_nodes = []
|
||||||
@@ -3443,6 +3451,7 @@ export class LGraphCanvas {
|
|||||||
|
|
||||||
item.selected = true
|
item.selected = true
|
||||||
this.selectedItems.add(item)
|
this.selectedItems.add(item)
|
||||||
|
this.state.selectionChanged = true
|
||||||
if (!(item instanceof LGraphNode)) return
|
if (!(item instanceof LGraphNode)) return
|
||||||
|
|
||||||
// Node-specific handling
|
// Node-specific handling
|
||||||
@@ -3475,6 +3484,7 @@ export class LGraphCanvas {
|
|||||||
|
|
||||||
item.selected = false
|
item.selected = false
|
||||||
this.selectedItems.delete(item)
|
this.selectedItems.delete(item)
|
||||||
|
this.state.selectionChanged = true
|
||||||
if (!(item instanceof LGraphNode)) return
|
if (!(item instanceof LGraphNode)) return
|
||||||
|
|
||||||
// Node-specific handling
|
// Node-specific handling
|
||||||
@@ -3613,6 +3623,7 @@ export class LGraphCanvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.state.selectionChanged = true
|
||||||
this.onSelectionChange?.(this.selected_nodes)
|
this.onSelectionChange?.(this.selected_nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3650,6 +3661,8 @@ export class LGraphCanvas {
|
|||||||
this.selectedItems.clear()
|
this.selectedItems.clear()
|
||||||
this.current_node = null
|
this.current_node = null
|
||||||
this.highlighted_links = {}
|
this.highlighted_links = {}
|
||||||
|
|
||||||
|
this.state.selectionChanged = true
|
||||||
this.onSelectionChange?.(this.selected_nodes)
|
this.onSelectionChange?.(this.selected_nodes)
|
||||||
this.setDirty(true)
|
this.setDirty(true)
|
||||||
graph.afterChange()
|
graph.afterChange()
|
||||||
|
|||||||
Reference in New Issue
Block a user