diff --git a/src/lib/litegraph/src/LGraphCanvas.dragStartDeferral.test.ts b/src/lib/litegraph/src/LGraphCanvas.dragStartDeferral.test.ts index 281a5b748f..8ec909336d 100644 --- a/src/lib/litegraph/src/LGraphCanvas.dragStartDeferral.test.ts +++ b/src/lib/litegraph/src/LGraphCanvas.dragStartDeferral.test.ts @@ -132,6 +132,18 @@ describe('_startDraggingItems defers onSelectionChange', () => { expect(onSelectionChange).not.toHaveBeenCalled() }) + it('invokes the deferred onSelectionChange with the canvas as receiver', () => { + const receivedThis: unknown[] = [] + canvas.onSelectionChange = function (this: unknown) { + receivedThis.push(this) + } + + canvas['_startDraggingItems'](node, pointer, true) + vi.advanceTimersByTime(16) + + expect(receivedThis).toEqual([canvas]) + }) + it('restores onSelectionChange even when processSelect throws', () => { const onSelectionChange = vi.fn() canvas.onSelectionChange = onSelectionChange diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index 5c320b9466..8193c392b8 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -3629,7 +3629,9 @@ export class LGraphCanvas implements CustomEventDispatcher this.onSelectionChange = onSelectionChange } if (onSelectionChange && selectionNotified) { - requestAnimationFrame(() => onSelectionChange(this.selected_nodes)) + requestAnimationFrame(() => { + onSelectionChange.call(this, this.selected_nodes) + }) } this.isDragging = true