mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
Add support for multiple changes in a single ChangeTracker state (#1022)
* wip * Add tests * Update package * remove logs * nit * nit --------- Co-authored-by: huchenlei <huchenlei@proton.me>
This commit is contained in:
@@ -12,6 +12,7 @@ export class ChangeTracker {
|
||||
activeState = null
|
||||
isOurLoad = false
|
||||
workflow: ComfyWorkflow | null
|
||||
changeCount = 0
|
||||
|
||||
ds: { scale: number; offset: [number, number] }
|
||||
nodeOutputs: any
|
||||
@@ -46,7 +47,7 @@ export class ChangeTracker {
|
||||
}
|
||||
|
||||
checkState() {
|
||||
if (!this.app.graph) return
|
||||
if (!this.app.graph || this.changeCount) return
|
||||
|
||||
const currentState = this.app.graph.serialize()
|
||||
if (!this.activeState) {
|
||||
@@ -100,6 +101,16 @@ export class ChangeTracker {
|
||||
}
|
||||
}
|
||||
|
||||
beforeChange() {
|
||||
this.changeCount++
|
||||
}
|
||||
|
||||
afterChange() {
|
||||
if (!--this.changeCount) {
|
||||
this.checkState()
|
||||
}
|
||||
}
|
||||
|
||||
static init(app: ComfyApp) {
|
||||
const changeTracker = () =>
|
||||
app.workflowManager.activeWorkflow?.changeTracker ?? globalTracker
|
||||
@@ -210,6 +221,15 @@ export class ChangeTracker {
|
||||
return v
|
||||
}
|
||||
|
||||
// Handle multiple commands as a single transaction
|
||||
document.addEventListener('litegraph:canvas', (e: CustomEvent) => {
|
||||
if (e.detail.subType === 'before-change') {
|
||||
changeTracker().beforeChange()
|
||||
} else if (e.detail.subType === 'after-change') {
|
||||
changeTracker().afterChange()
|
||||
}
|
||||
})
|
||||
|
||||
// Store node outputs
|
||||
api.addEventListener('executed', ({ detail }) => {
|
||||
const prompt =
|
||||
|
||||
Reference in New Issue
Block a user