Skip to content

Commit 50a78bb

Browse files
committed
test(spatial): add 5px drag threshold to DisplayNote pointer events
- Add clientX/clientY coordinates to pointerdown test event - Add pointermove trigger with 10px offset to exceed 5px threshold - Update comment to reference legacy listenPointerEvents behavior - Defer isDragging flag and dragstart emission until 5px movement detected - Move cursor change to grabbing inside threshold check - Only emit dragend and reset cursor if isDragging was true - Remove hasDragged flag reset (still used for click
1 parent 4710535 commit 50a78bb

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

new-deepnotes/apps/web/src/features/spatial/DisplayNote.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ describe("DisplayNote", () => {
215215

216216
const el = wrapper.find('[data-testid="display-note"]');
217217
mockPointerCapture(el);
218-
await el.trigger('pointerdown', { button: 0 });
218+
await el.trigger('pointerdown', { button: 0, clientX: 0, clientY: 0 });
219+
// Dragging only starts after 5px threshold (like legacy listenPointerEvents)
220+
await el.trigger('pointermove', { clientX: 10, clientY: 0 });
219221
expect(wrapper.emitted('dragstart')).toHaveLength(1);
220222
});
221223

new-deepnotes/apps/web/src/features/spatial/DisplayNote.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,28 @@ function onPointerDown(e: PointerEvent) {
233233
noteStartX = props.model.pos.value.x;
234234
noteStartY = props.model.pos.value.y;
235235
hasDragged = false;
236-
isDragging.value = true;
237-
emit("dragstart", props.id);
236+
// Don't start dragging yet; wait for 5px threshold (like legacy listenPointerEvents)
238237
const el = e.currentTarget as HTMLElement;
239238
el.setPointerCapture(e.pointerId);
240-
el.style.cursor = "grabbing";
241239
}
242240
243241
function onPointerMove(e: PointerEvent) {
244242
if (dragPointerId !== e.pointerId) return;
243+
245244
const dxScreen = e.clientX - startX;
246245
const dyScreen = e.clientY - startY;
247-
if (dxScreen !== 0 || dyScreen !== 0) {
246+
247+
if (!isDragging.value) {
248+
if (Math.sqrt(dxScreen * dxScreen + dyScreen * dyScreen) <= 5) {
249+
return;
250+
}
251+
isDragging.value = true;
248252
hasDragged = true;
253+
emit("dragstart", props.id);
254+
const el = e.currentTarget as HTMLElement;
255+
el.style.cursor = "grabbing";
249256
}
257+
250258
const z = props.zoom || 1;
251259
const noteMap = props.model.rawMap;
252260
const posMap = noteMap.get("pos") as import("yjs").Map<number>;
@@ -265,10 +273,9 @@ function onPointerUp(e: PointerEvent) {
265273
/* ignore */
266274
}
267275
}
268-
el.style.cursor = props.model.movable.value ? "grab" : "";
269-
isDragging.value = false;
270-
if (hasDragged) {
271-
hasDragged = false;
276+
if (isDragging.value) {
277+
el.style.cursor = props.model.movable.value ? "grab" : "";
278+
isDragging.value = false;
272279
emit("dragend", props.id);
273280
}
274281
}

0 commit comments

Comments
 (0)