From b1006e2bfd0a8452ab47977c56e0a9ecc920b00c Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Sun, 14 Sep 2025 14:05:55 +0200 Subject: [PATCH] fix: Locked elbow arrow creation --- packages/element/src/linearElementEditor.ts | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index 4a89f21ca..6905497a0 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -397,9 +397,11 @@ export class LinearElementEditor { ): Pick | null { const elementsMap = app.scene.getNonDeletedElementsMap(); const elements = app.scene.getNonDeletedElements(); - const { elbowed, elementId, initialState, selectedPointsIndices } = - linearElementEditor; - const { lastClickedPoint } = initialState; + const { elbowed, elementId, initialState } = linearElementEditor; + const selectedPointsIndices = Array.from( + linearElementEditor.selectedPointsIndices ?? [], + ); + let { lastClickedPoint } = initialState; const element = LinearElementEditor.getElement(elementId, elementsMap); invariant(element, "Element being dragged must exist in the scene"); @@ -411,6 +413,18 @@ export class LinearElementEditor { "There must be selected points in order to drag them", ); + if (elbowed) { + selectedPointsIndices.some((pointIdx, idx) => { + if (pointIdx > 0 && pointIdx !== element.points.length - 1) { + selectedPointsIndices[idx] = element.points.length - 1; + lastClickedPoint = element.points.length - 1; + return true; + } + + return false; + }); + } + invariant( lastClickedPoint > -1 && selectedPointsIndices.includes(lastClickedPoint) && @@ -422,16 +436,6 @@ export class LinearElementEditor { }) lastClickedPoint(${lastClickedPoint})`, ); - invariant( - !elbowed || - selectedPointsIndices?.filter( - (idx) => idx !== 0 && idx !== element.points.length - 1, - ).length === 0, - `Only start and end points can be selected for elbow arrows: ${JSON.stringify( - selectedPointsIndices, - )} end point ${element.points.length - 1}`, - ); - // point that's being dragged (out of all selected points) const draggingPoint = element.points[lastClickedPoint]; // The adjacent point to the one dragged point