From cea5f0b721a1b73993259ee67390f87379052d0d Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Sat, 2 May 2026 17:17:50 +0900 Subject: [PATCH] fix: restore ghost placement cancellation handling --- src/lib/litegraph/src/LGraphCanvas.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index f7f0f54b4a..5d5f4d5664 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -684,6 +684,7 @@ export class LGraphCanvas implements CustomEventDispatcher private _visibleReroutes: Set = 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 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 * @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 '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 this._ghostPointerHandler = null } + if (this._ghostKeyHandler) { + document.removeEventListener('keydown', this._ghostKeyHandler, true) + this._ghostKeyHandler = null + } + const node = this.graph?.getNodeById(nodeId) if (!node) return