From 4dafab1d141ca7e5cf3abc7aa41a91661a80e77d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 24 Aug 2025 10:37:23 +0000 Subject: [PATCH] Fix pointer events click prevention after drag and drop Co-authored-by: lavrton <1443320+lavrton@users.noreply.github.com> --- src/DragAndDrop.ts | 5 +++++ src/Node.ts | 2 +- test/unit/DragAndDropEvents-test.ts | 2 +- test/unit/test-utils.ts | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/DragAndDrop.ts b/src/DragAndDrop.ts index 3eeb9a12..f645e216 100644 --- a/src/DragAndDrop.ts +++ b/src/DragAndDrop.ts @@ -163,11 +163,16 @@ if (Konva.isBrowser) { window.addEventListener('touchend', DD._endDragBefore, true); // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843 window.addEventListener('touchcancel', DD._endDragBefore, true); + window.addEventListener('pointerup', DD._endDragBefore, true); + window.addEventListener('pointercancel', DD._endDragBefore, true); window.addEventListener('mousemove', DD._drag); window.addEventListener('touchmove', DD._drag); + window.addEventListener('pointermove', DD._drag); window.addEventListener('mouseup', DD._endDragAfter, false); window.addEventListener('touchend', DD._endDragAfter, false); window.addEventListener('touchcancel', DD._endDragAfter, false); + window.addEventListener('pointerup', DD._endDragAfter, false); + window.addEventListener('pointercancel', DD._endDragAfter, false); } diff --git a/src/Node.ts b/src/Node.ts index 25f48cf5..3d1baee2 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -2665,7 +2665,7 @@ export abstract class Node { _listenDrag() { this._dragCleanup(); - this.on('mousedown.konva touchstart.konva', function (evt) { + this.on('mousedown.konva touchstart.konva pointerdown.konva', function (evt) { const shouldCheckButton = evt.evt['button'] !== undefined; const canDrag = !shouldCheckButton || Konva.dragButtons.indexOf(evt.evt['button']) >= 0; diff --git a/test/unit/DragAndDropEvents-test.ts b/test/unit/DragAndDropEvents-test.ts index 3395a6a3..3d426790 100644 --- a/test/unit/DragAndDropEvents-test.ts +++ b/test/unit/DragAndDropEvents-test.ts @@ -251,7 +251,7 @@ describe('DragAndDropEvents', function () { // should we save several pointers per shape? // doesn't sound good // switch to pointer only event handling? - it.skip('click should not occur after drag and drop', function (done) { + it('click should not occur after drag and drop - pointer events', function (done) { var stage = addStage(); var layer = new Konva.Layer(); diff --git a/test/unit/test-utils.ts b/test/unit/test-utils.ts index 4919a7a0..1901e824 100644 --- a/test/unit/test-utils.ts +++ b/test/unit/test-utils.ts @@ -377,7 +377,7 @@ export function simulatePointerMove(stage: Stage, pos: SimulatedPointerEvent) { }; stage._pointermove(evt as any); - // Konva.DD._drag(evt); + Konva.DD._drag(evt); } export function simulatePointerUp(stage: Stage, pos: SimulatedPointerEvent) { @@ -390,9 +390,9 @@ export function simulatePointerUp(stage: Stage, pos: SimulatedPointerEvent) { type: 'pointerup', }; - // Konva.DD._endDragBefore(evt); + Konva.DD._endDragBefore(evt); stage._pointerup(evt as any); - // Konva.DD._endDragAfter(evt); + Konva.DD._endDragAfter(evt); } function isClose(a, b) {