From 7360e091724a7b6eb771341c72a3e2dca14e6eab Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 6 Apr 2025 23:31:09 +1000 Subject: [PATCH] Standardise right-click behaviour (#894) - Uses CanvasPointer click to open context menu (formerly occurred on `pointerdown`) - Frees up right-click & drag to be used by future features - Right-clicking a reroute now selects the reroute, using the same selection logic used for right-clicking nodes --- src/LGraphCanvas.ts | 10 ++++++++-- src/LiteGraphGlobal.ts | 19 ++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index f406fcd31..0720d530a 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -1877,10 +1877,16 @@ export class LGraphCanvas implements ConnectionColorContext { // Right / aux button // Sticky select - won't remove single nodes - if (node) this.processSelect(node, e, true) + if (node) { + this.processSelect(node, e, true) + } else if (this.links_render_mode !== LinkRenderType.HIDDEN_LINK) { + // Reroutes + const reroute = graph.getRerouteOnPos(e.canvasX, e.canvasY) + if (reroute) this.processSelect(reroute, e, true) + } // Show context menu for the node or group under the pointer - this.processContextMenu(node, e) + pointer.onClick = () => this.processContextMenu(node, e) } this.last_mouse = [x, y] diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index a09f22d4c..3c373591f 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -788,22 +788,15 @@ export class LiteGraphGlobal { return hex } - closeAllContextMenus(ref_window: Window): void { - ref_window = ref_window || window - - const elements = ref_window.document.querySelectorAll(".litecontextmenu") + closeAllContextMenus(ref_window: Window = window): void { + const elements = [...ref_window.document.querySelectorAll(".litecontextmenu")] if (!elements.length) return - const results = [] for (const element of elements) { - results.push(element) - } - - for (const result of results) { - if ("close" in result && typeof result.close === "function") { - result.close() - } else if (result.parentNode) { - result.remove() + if ("close" in element && typeof element.close === "function") { + element.close() + } else { + element.remove() } } }