From 2f0e3d35d3dc719f64e9c81ed13d7527977a5c68 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:23:38 +1000 Subject: [PATCH] [CodeHealth] Standardise code in processKey (#985) --- src/LGraphCanvas.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 5564a5a19c..7ce26e01bb 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2979,9 +2979,11 @@ export class LGraphCanvas { /** * process a key event */ - processKey(e: KeyboardEvent): boolean | null | undefined { + processKey(e: KeyboardEvent): void { this.#shiftDown = e.shiftKey - if (!this.graph) return + + const { graph } = this + if (!graph) return let block_default = false // @ts-expect-error @@ -3030,13 +3032,9 @@ export class LGraphCanvas { } } - // collapse - // ... // TODO - if (this.selected_nodes) { - for (const i in this.selected_nodes) { - this.selected_nodes[i].onKeyDown?.(e) - } + for (const node of Object.values(this.selected_nodes)) { + node.onKeyDown?.(e) } } else if (e.type == "keyup") { if (e.key === " ") { @@ -3046,20 +3044,17 @@ export class LGraphCanvas { this._previously_dragging_canvas = null } - if (this.selected_nodes) { - for (const i in this.selected_nodes) { - this.selected_nodes[i].onKeyUp?.(e) - } + for (const node of Object.values(this.selected_nodes)) { + node.onKeyUp?.(e) } } // TODO: Do we need to remeasure and recalculate everything on every key down/up? - this.graph.change() + graph.change() if (block_default) { e.preventDefault() e.stopImmediatePropagation() - return false } }