From f2eafae82da9748683bc51cde567ecbf641bfc3a Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 3 May 2025 23:49:33 +1000 Subject: [PATCH] Add no-items-selected event (#1004) Emits an event when attempting to delete items with nothing selected. Event is generic and should also be used to report any other user-initiated actions. Emitted from LGraphCanvas.canvas - bubbles - non-cancellable ``` litegraph:no-items-selected ``` --- src/LGraphCanvas.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index f27c1449b..8b0c61457 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2979,6 +2979,11 @@ export class LGraphCanvas { return } + #noItemsSelected(): void { + const event = new CustomEvent("litegraph:no-items-selected", { bubbles: true }) + this.canvas.dispatchEvent(event) + } + /** * process a key event */ @@ -3030,6 +3035,11 @@ export class LGraphCanvas { // delete or backspace // @ts-expect-error if (e.target.localName != "input" && e.target.localName != "textarea") { + if (this.selectedItems.size === 0) { + this.#noItemsSelected() + return + } + this.deleteSelected() block_default = true }