From ca8e31c6959015e0944201b4bfdda7541ee72030 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 11 Nov 2024 01:40:36 +1100 Subject: [PATCH] Emit only one change when deleting nodes (#296) --- src/LGraphCanvas.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index ba1de3002..99354c09a 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2971,12 +2971,14 @@ export class LGraphCanvas { )) } + /** @todo Refactor to where it belongs - e.g. Deleting / creating nodes is not actually canvas event. */ emitBeforeChange(): void { this.emitEvent({ subType: "before-change", }) } + /** @todo See {@link emitBeforeChange} */ emitAfterChange(): void { this.emitEvent({ subType: "after-change", @@ -3314,9 +3316,12 @@ export class LGraphCanvas { /** * Deletes all selected items from the graph. + * + * @todo Refactor deletion task to LGraph. Selection is a canvas property, delete is a graph action. */ deleteSelected(): void { const { graph } = this + this.emitBeforeChange() graph.beforeChange() for (const item of this.selectedItems) { @@ -3337,6 +3342,7 @@ export class LGraphCanvas { this.highlighted_links = {} this.setDirty(true) graph.afterChange() + this.emitAfterChange() } /**