mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-23 22:25:05 +00:00
fix: restore ghost placement cancellation handling
This commit is contained in:
@@ -684,6 +684,7 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
|
||||
private _visibleReroutes: Set<Reroute> = new Set()
|
||||
private _autoPan: AutoPanController | null = null
|
||||
private _ghostPointerHandler: ((e: PointerEvent) => void) | null = null
|
||||
private _ghostKeyHandler: ((e: KeyboardEvent) => void) | null = null
|
||||
|
||||
dirty_canvas: boolean = true
|
||||
dirty_bgcanvas: boolean = true
|
||||
@@ -1860,6 +1861,8 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
|
||||
const { graph } = this
|
||||
if (newGraph === graph) return
|
||||
|
||||
if (this.state.ghostNodeId != null) this.finalizeGhostPlacement(true)
|
||||
|
||||
this.clear()
|
||||
newGraph.attachCanvas(this)
|
||||
|
||||
@@ -3667,6 +3670,8 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
|
||||
* @param dragEvent Optional mouse event for positioning under cursor
|
||||
*/
|
||||
startGhostPlacement(node: LGraphNode, dragEvent?: MouseEvent): void {
|
||||
if (this.state.ghostNodeId != null) this.finalizeGhostPlacement(true)
|
||||
|
||||
this.emitBeforeChange()
|
||||
this.graph?.beforeChange()
|
||||
|
||||
@@ -3706,6 +3711,17 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
|
||||
'pointerleave',
|
||||
this._ghostPointerHandler
|
||||
)
|
||||
|
||||
this._ghostKeyHandler = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Escape' && e.key !== 'Delete' && e.key !== 'Backspace') {
|
||||
return
|
||||
}
|
||||
|
||||
this.finalizeGhostPlacement(true)
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
}
|
||||
document.addEventListener('keydown', this._ghostKeyHandler, true)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3734,6 +3750,11 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
|
||||
this._ghostPointerHandler = null
|
||||
}
|
||||
|
||||
if (this._ghostKeyHandler) {
|
||||
document.removeEventListener('keydown', this._ghostKeyHandler, true)
|
||||
this._ghostKeyHandler = null
|
||||
}
|
||||
|
||||
const node = this.graph?.getNodeById(nodeId)
|
||||
if (!node) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user