Skip to content

Commit 2ae3c55

Browse files
committed
feat: drag drop was happening even on slightest mouse movements which is unexpected
1 parent 8156e63 commit 2ae3c55

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,8 @@ function RemoteFunctions(config = {}) {
15321532
function onDragStart(event, element) {
15331533
event.stopPropagation();
15341534
event.dataTransfer.setData("text/plain", element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR));
1535+
window._dragStartX = event.clientX;
1536+
window._dragStartY = event.clientY;
15351537
_dragStartChores(element);
15361538
_clearDropMarkers();
15371539
window._currentDraggedElement = element;
@@ -1547,6 +1549,8 @@ function RemoteFunctions(config = {}) {
15471549
_clearDropMarkers();
15481550
_stopAutoScroll();
15491551
delete window._currentDraggedElement;
1552+
delete window._dragStartX;
1553+
delete window._dragStartY;
15501554
}
15511555

15521556
/**
@@ -1635,6 +1639,27 @@ function RemoteFunctions(config = {}) {
16351639
event.preventDefault();
16361640
event.stopPropagation();
16371641

1642+
// this is to validate that actual drag happened, otherwise sometimes just little mouse movements was causing
1643+
// the drag to happen which was unexpected
1644+
const DRAG_THRESHOLD = 5;
1645+
1646+
if (window._dragStartX !== undefined && window._dragStartY !== undefined) {
1647+
const deltaX = Math.abs(event.clientX - window._dragStartX);
1648+
const deltaY = Math.abs(event.clientY - window._dragStartY);
1649+
1650+
if (deltaX <= DRAG_THRESHOLD && deltaY <= DRAG_THRESHOLD) {
1651+
_clearDropMarkers();
1652+
_stopAutoScroll();
1653+
_dragEndChores(window._currentDraggedElement);
1654+
dismissUIAndCleanupState();
1655+
delete window._currentDraggedElement;
1656+
delete window._dragStartX;
1657+
delete window._dragStartY;
1658+
delete window._isDraggingSVG;
1659+
return;
1660+
}
1661+
}
1662+
16381663
let target = _lastDragTarget;
16391664

16401665
if (!target) {
@@ -1707,6 +1732,8 @@ function RemoteFunctions(config = {}) {
17071732
_dragEndChores(window._currentDraggedElement);
17081733
dismissUIAndCleanupState();
17091734
delete window._currentDraggedElement;
1735+
delete window._dragStartX;
1736+
delete window._dragStartY;
17101737
}
17111738

17121739
/**
@@ -1718,6 +1745,8 @@ function RemoteFunctions(config = {}) {
17181745
event.preventDefault();
17191746
event.stopPropagation();
17201747

1748+
window._dragStartX = event.clientX;
1749+
window._dragStartY = event.clientY;
17211750
window._currentDraggedElement = element;
17221751
_dragStartChores(element);
17231752
_clearDropMarkers();

0 commit comments

Comments
 (0)