Browse Source

fix: snap to grid of arrow handlers

Konstantinos Kaloutas 2 years ago
parent
commit
ace5ba56e1

+ 3 - 6
tldraw/packages/core/src/lib/TLBaseLineBindingState.ts

@@ -7,7 +7,7 @@ import type { TLLineShape, TLLineShapeProps, TLShape } from './shapes'
 import type { TLApp } from './TLApp'
 import type { TLTool } from './TLTool'
 import { TLToolState } from './TLToolState'
-
+import { GRID_SIZE } from '@tldraw/core'
 export class TLBaseLineBindingState<
   S extends TLShape,
   T extends S & TLLineShape,
@@ -30,8 +30,7 @@ export class TLBaseLineBindingState<
   onPointerMove: TLStateEvents<S, K>['onPointerMove'] = () => {
     const {
       inputs: { shiftKey, previousPoint, originPoint, currentPoint, modKey, altKey },
-      settings: { showGrid },
-      currentGrid,
+      settings: { snapToGrid },
     } = this.app
     // @ts-expect-error just ignore
     const shape = this.app.getShapeById<TLLineShape>(this.initialShape.id)!
@@ -56,9 +55,7 @@ export class TLBaseLineBindingState<
     const handleChanges = {
       [handleId]: {
         ...handles[handleId],
-        // FIXME Snap not working properly
-        // point: showGrid ? Vec.snap(nextPoint, currentGrid) : Vec.toFixed(nextPoint)
-        point: Vec.toFixed(nextPoint),
+        point: snapToGrid ? Vec.snap(nextPoint, GRID_SIZE) : Vec.toFixed(nextPoint),
         bindingId: undefined,
       },
     }

+ 3 - 1
tldraw/packages/core/src/lib/tools/TLLineTool/states/CreatingState.tsx

@@ -5,6 +5,8 @@ import type { TLShape, TLLineShape } from '../../../shapes'
 import type { TLApp } from '../../../TLApp'
 import { TLBaseLineBindingState } from '../../../TLBaseLineBindingState'
 import type { TLLineTool } from '../TLLineTool'
+import Vec from '@tldraw/vec'
+import { GRID_SIZE } from '@tldraw/core'
 
 export class CreatingState<
   S extends TLShape,
@@ -31,7 +33,7 @@ export class CreatingState<
       id: uniqueId(),
       type: Shape.id,
       parentId: this.app.currentPage.id,
-      point: originPoint,
+      point: this.app.settings.snapToGrid ? Vec.snap(originPoint, GRID_SIZE) : originPoint,
       fill: this.app.settings.color,
       stroke: this.app.settings.color,
       scaleLevel: this.app.settings.scaleLevel,