From 3f9c6299a093f6a9a7e63dca4f15eacabc4842a1 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Wed, 9 Apr 2025 12:15:04 +0200 Subject: [PATCH] Fix the grid and angle lock Signed-off-by: Mark Tolmacs --- packages/excalidraw/linear.ts | 67 ++++++++++++----------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/packages/excalidraw/linear.ts b/packages/excalidraw/linear.ts index fbbe31a066..8419921577 100644 --- a/packages/excalidraw/linear.ts +++ b/packages/excalidraw/linear.ts @@ -96,13 +96,7 @@ export function onPointerMoveFromPointerDownOnLinearElement( { points: [ ...points, - LinearElementEditor.createPointAt( - newElement, - elementsMap, - x, - y, - app.getEffectiveGridSize(), - ), + pointFrom(x - newElement.x, y - newElement.y), ], }, false, @@ -111,35 +105,28 @@ export function onPointerMoveFromPointerDownOnLinearElement( points.length === 2 || (points.length > 1 && isElbowArrow(newElement)) ) { - const targets = [ - { + const targets = []; + + if (isArrowElement(newElement)) { + const [endX, endY] = getOutlineAvoidingPoint( + newElement, + pointFrom(pointerCoords.x, pointerCoords.y), + points.length - 1, + app.scene, + app.state.zoom, + pointFrom(newElement.x + dx, newElement.y + dy), + ); + + targets.push({ + index: points.length - 1, + isDragging: true, + point: pointFrom(endX - newElement.x, endY - newElement.y), + }); + } else { + targets.push({ index: points.length - 1, isDragging: true, point: pointFrom(dx, dy), - }, - ]; - - if (isArrowElement(newElement)) { - const [x, y] = getOutlineAvoidingPoint( - newElement, - pointFrom( - pointerDownState.origin.x, - pointerDownState.origin.y, - ), - 0, - app.scene, - app.state.zoom, - ); - targets.unshift({ - index: 0, - isDragging: false, - point: LinearElementEditor.createPointAt( - newElement, - elementsMap, - x, - y, - app.getEffectiveGridSize(), - ), }); } @@ -223,11 +210,9 @@ export function handleCanvasPointerMoveForLinearElement( const [gridX, gridY] = getGridPoint( scenePointerX, scenePointerY, - event[KEYS.CTRL_OR_CMD] || isElbowArrow(multiElement) - ? null - : app.getEffectiveGridSize(), + event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(), ); - console.log(points); + const [lastCommittedX, lastCommittedY] = multiElement?.lastCommittedPoint ?? [0, 0]; @@ -268,13 +253,7 @@ export function handleCanvasPointerMoveForLinearElement( LinearElementEditor.movePoints(multiElement, [ { index: points.length - 1, - point: LinearElementEditor.createPointAt( - multiElement, - app.scene.getNonDeletedElementsMap(), - x, - y, - app.getEffectiveGridSize(), - ), + point: pointFrom(x - multiElement.x, y - multiElement.y), isDragging: true, }, ]);