@@ -73,7 +73,6 @@ export function useDrag(params: UseDragParams) {
73
73
let mousePosition : XYPosition = { x : 0 , y : 0 }
74
74
let dragEvent : MouseEvent | null = null
75
75
let dragStarted = false
76
- let dragAborted = false
77
76
78
77
let autoPanId = 0
79
78
let autoPanStarted = false
@@ -218,9 +217,6 @@ export function useDrag(params: UseDragParams) {
218
217
if ( distance > nodeDragThreshold . value ) {
219
218
startDrag ( event , nodeEl )
220
219
}
221
-
222
- // we have to ignore very small movements as they would be picked up as regular clicks even though a potential drag might have been registered as well
223
- dragAborted = distance >= 0.5 && distance < nodeDragThreshold . value
224
220
}
225
221
226
222
// skip events without movement
@@ -234,10 +230,15 @@ export function useDrag(params: UseDragParams) {
234
230
235
231
const eventEnd = ( event : UseDragEvent ) => {
236
232
if ( ! dragStarted ) {
237
- // if the node was dragged without any movement, and we're not dragging a selection, we want to emit the node-click event
238
- if ( dragAborted && onClick ) {
233
+ const pointerPos = getPointerPosition ( event )
234
+
235
+ const x = pointerPos . xSnapped - ( lastPos . x ?? 0 )
236
+ const y = pointerPos . ySnapped - ( lastPos . y ?? 0 )
237
+ const distance = Math . sqrt ( x * x + y * y )
238
+
239
+ // dispatch a click event if the node was attempted to be dragged but the threshold was not exceeded
240
+ if ( distance !== 0 && distance <= nodeDragThreshold . value ) {
239
241
onClick ?.( event . sourceEvent )
240
- dragAborted = false
241
242
}
242
243
243
244
return
@@ -246,7 +247,6 @@ export function useDrag(params: UseDragParams) {
246
247
dragging . value = false
247
248
autoPanStarted = false
248
249
dragStarted = false
249
- dragAborted = false
250
250
251
251
cancelAnimationFrame ( autoPanId )
252
252
0 commit comments