From 8ba96aed9a9690f9ab88e0217baca678b749ea12 Mon Sep 17 00:00:00 2001 From: dominicteh1 <144811250+dominicteh1@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:41:21 -0500 Subject: [PATCH] fix: elbow arrow endpoint drag with Ctrl held does not snap but tries to select (#12) * change snapping logic * remove selection box * snapping * formatted with prettier --------- Co-authored-by: Michaelli8899 <147345359+Michaelli8899@users.noreply.github.com> --- .../excalidraw/element/linearElementEditor.ts | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/excalidraw/element/linearElementEditor.ts b/packages/excalidraw/element/linearElementEditor.ts index 0cb537801..df31598a4 100644 --- a/packages/excalidraw/element/linearElementEditor.ts +++ b/packages/excalidraw/element/linearElementEditor.ts @@ -298,20 +298,44 @@ export class LinearElementEditor { const snapAngle = Math.round(angle / 15) * 15; // Only remove midpoints for cardinal angles if ([0, 90, 180, 270, 360].includes(snapAngle)) { - const newPoints = [ - element.points[0], - element.points[element.points.length - 1], - ]; + const { x: rx, y: ry } = element; + const [gridX, gridY] = getGridPoint( + scenePointerX, + scenePointerY, + null, + ); + + const [lastCommittedX, lastCommittedY] = + element.lastCommittedPoint ?? [0, 0]; + + let dxFromLastCommitted = gridX - rx - lastCommittedX; + let dyFromLastCommitted = gridY - ry - lastCommittedY; + + ({ width: dxFromLastCommitted, height: dyFromLastCommitted } = + getLockedLinearCursorAlignSize( + // actual coordinate of the last committed point + lastCommittedX + rx, + lastCommittedY + ry, + // cursor-grid coordinate + gridX, + gridY, + )); mutateElbowArrow( element, elementsMap, - newPoints, - vector(0, 0), + [ + ...element.points.slice(0, -1), + pointFrom( + lastCommittedX + dxFromLastCommitted, + lastCommittedY + dyFromLastCommitted, + ), + ], + undefined, + undefined, { - startBinding: element.startBinding, - endBinding: element.endBinding, + isDragging: true, + informMutation: false, }, - { isDragging: true }, ); if (selectedIndex > 0) { selectedIndex = 1; @@ -321,7 +345,7 @@ export class LinearElementEditor { const referencePoint = element.points[selectedIndex === 0 ? 1 : selectedIndex - 1]; - + const [width, height] = LinearElementEditor._getShiftLockedDelta( element, elementsMap,