From 021e54895bac9a4b0980d623d235d06cf9216213 Mon Sep 17 00:00:00 2001 From: dmitrykurmanov Date: Mon, 5 Aug 2024 16:49:33 +0400 Subject: [PATCH] work for the https://github.com/surveyjs/survey-creator/issues/5740 --- src/dragdrop/core.ts | 3 ++- tests/dragdrophelpertests.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dragdrop/core.ts b/src/dragdrop/core.ts index e8a9fd7a9a..30ac0b54b6 100644 --- a/src/dragdrop/core.ts +++ b/src/dragdrop/core.ts @@ -63,6 +63,8 @@ export abstract class DragDropCore implements IDragDropEngine { event ); this.onStartDrag(event); + const fromElement = this.draggedElement.parent; + this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); } protected onStartDrag(event?: PointerEvent): void { @@ -230,7 +232,6 @@ export abstract class DragDropCore implements IDragDropEngine { public drop(): void { if (this.allowDropHere) { const fromElement = this.draggedElement.parent; - this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); const newElement = this.doDrop(); this.onDragEnd.fire(this, { fromElement: fromElement, draggedElement: newElement, toElement: this.dropTarget }); } diff --git a/tests/dragdrophelpertests.ts b/tests/dragdrophelpertests.ts index 7dd074b581..8e165e645e 100644 --- a/tests/dragdrophelpertests.ts +++ b/tests/dragdrophelpertests.ts @@ -144,12 +144,14 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { ddHelper.parentElement = question; ddHelper.draggedElement = question.choices[2]; + ddHelper["createDraggedElementShortcut"] = ()=>{}; + ddHelper.dragInit(null, ddHelper.draggedElement, ddHelper.parentElement, document.createElement("div")); + assert.equal(beforeCount, 1); + ddHelper["allowDropHere"] = true; ddHelper["domAdapter"]["draggedElementShortcut"] = document.body.appendChild( document.createElement("div") ); - ddHelper["allowDropHere"] = true; ddHelper["drop"](); - assert.equal(beforeCount, 1); assert.equal(afterCount, 1); assert.equal(draggedElementParent.name, "q"); });