Skip to content

Commit 2243f0c

Browse files
committed
fix(canvas): snap whole-line drag to absolute grid, not delta
Snapping the drag delta meant an off-grid line (e.g. x=11 imported into a snap=8 grid) would stay off-grid forever — drag delta of 8 yields x=19 instead of grid-aligned x=16. Snap the absolute start position instead and derive the delta from the snap result, mirroring the endpoint-handle drag in this same file and the shape/text/image drag elsewhere.
1 parent 0e32253 commit 2243f0c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎src/components/Canvas/LineObject.tsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ export function LineObject({
8686
}
8787
onTap={() => onSelect(false)}
8888
onDragMove={(e) => {
89-
// Snap the whole-line delta in dot space, then mirror back
90-
// to pixels — same idiom the endpoint handles use, and
91-
// keeps the line consistent with shape/text/image drag.
92-
const deltaXPx =
93-
dotsToPx(snap(pxToDots(e.target.x(), scale, dpmm)), scale, dpmm);
94-
const deltaYPx =
95-
dotsToPx(snap(pxToDots(e.target.y(), scale, dpmm)), scale, dpmm);
89+
// Snap the absolute start-point position to the grid (not
90+
// the delta), then derive the delta to apply. Snapping the
91+
// delta would let an off-grid line stay off-grid forever;
92+
// shapes, text and the endpoint handles in this same
93+
// component all snap absolute, so the line should too.
94+
const newX = snap(obj.x + pxToDots(e.target.x(), scale, dpmm));
95+
const newY = snap(obj.y + pxToDots(e.target.y(), scale, dpmm));
96+
const deltaXPx = dotsToPx(newX - obj.x, scale, dpmm);
97+
const deltaYPx = dotsToPx(newY - obj.y, scale, dpmm);
9698
e.target.position({ x: deltaXPx, y: deltaYPx });
9799
setDragDelta({ x: deltaXPx, y: deltaYPx });
98100
}}

0 commit comments

Comments
 (0)