From 0764437642fd2f5c04b90460a9eb1eac35a24548 Mon Sep 17 00:00:00 2001 From: "Janus C. H. Knudsen" Date: Sat, 11 Oct 2025 01:38:15 +0200 Subject: [PATCH] Moves drag:move emission to animation loop Ensures drag:move events are emitted during the animation loop for smoother and more consistent updates during drag operations. Removes redundant emission from the main drag handling logic. --- src/managers/DragDropManager.ts | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/managers/DragDropManager.ts b/src/managers/DragDropManager.ts index 7ea7496..347f15f 100644 --- a/src/managers/DragDropManager.ts +++ b/src/managers/DragDropManager.ts @@ -298,19 +298,6 @@ export class DragDropManager { this.currentY = parseFloat(this.draggedClone!.style.top) || 0; this.animateDrag(); } - - // Emit drag:move event with current draggedClone reference - if (this.draggedClone) { - const dragMovePayload: DragMoveEventPayload = { - draggedElement: this.draggedElement!, - draggedClone: this.draggedClone, - mousePosition: currentPosition, - snappedY: this.currentY, - columnBounds: column, - mouseOffset: this.mouseOffset - }; - this.eventBus.emit('drag:move', dragMovePayload); - } } // Check for auto-scroll @@ -478,7 +465,7 @@ export class DragDropManager { /** * Smooth drag animation using requestAnimationFrame - * Only interpolates currentY - events are emitted from continueDrag() + * Emits drag:move events with current draggedClone reference on each frame */ private animateDrag(): void { if (!this.isDragStarted || !this.draggedClone || !this.targetColumn) { @@ -493,10 +480,34 @@ export class DragDropManager { // Update if difference is significant if (Math.abs(diff) > 0.5) { this.currentY += step; + + // Emit drag:move event with current draggedClone reference + const dragMovePayload: DragMoveEventPayload = { + draggedElement: this.draggedElement!, + draggedClone: this.draggedClone, // Always uses current reference + mousePosition: this.lastMousePosition, + snappedY: this.currentY, + columnBounds: this.targetColumn, + mouseOffset: this.mouseOffset + }; + this.eventBus.emit('drag:move', dragMovePayload); + this.dragAnimationId = requestAnimationFrame(() => this.animateDrag()); } else { // Close enough - snap to target this.currentY = this.targetY; + + // Emit final position + const dragMovePayload: DragMoveEventPayload = { + draggedElement: this.draggedElement!, + draggedClone: this.draggedClone, + mousePosition: this.lastMousePosition, + snappedY: this.currentY, + columnBounds: this.targetColumn, + mouseOffset: this.mouseOffset + }; + this.eventBus.emit('drag:move', dragMovePayload); + this.dragAnimationId = null; } }