diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 43043f610..cb06e5519 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -8730,7 +8730,7 @@ export class Editor extends EventEmitter { if ( inputs.isPointing && !inputs.isDragging && - Vec.Dist2(originPagePoint, currentPagePoint) > + Vec.Dist2(originPagePoint, currentPagePoint) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / diff --git a/packages/tldraw/src/test/Editor.test.tsx b/packages/tldraw/src/test/Editor.test.tsx index 13b16bc63..c1d063c4d 100644 --- a/packages/tldraw/src/test/Editor.test.tsx +++ b/packages/tldraw/src/test/Editor.test.tsx @@ -678,3 +678,39 @@ describe('middle-click panning', () => { expect(editor.inputs.isPanning).toBe(false) }) }) + +describe('dragging', () => { + it('drags correctly at 100% zoom', () => { + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 0).pointerDown() + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 1) + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 5) + expect(editor.inputs.isDragging).toBe(true) + }) + + it('drags correctly at 150% zoom', () => { + editor.setCamera({ x: 0, y: 0, z: 8 }).forceTick() + + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 0).pointerDown() + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 2) + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 5) + expect(editor.inputs.isDragging).toBe(true) + }) + + it('drags correctly at 50% zoom', () => { + editor.setCamera({ x: 0, y: 0, z: 0.1 }).forceTick() + + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 0).pointerDown() + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 2) + expect(editor.inputs.isDragging).toBe(false) + editor.pointerMove(0, 5) + expect(editor.inputs.isDragging).toBe(true) + }) +})