From 4ffe7fd99144eb20814544dbceb0e90e3c06fe17 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Thu, 1 May 2025 09:07:50 +0200 Subject: [PATCH] Additional fixes Signed-off-by: Mark Tolmacs --- .../excalidraw/actions/actionFinalize.tsx | 61 ++++++++++--------- packages/excalidraw/components/App.tsx | 22 ------- .../tests/__snapshots__/move.test.tsx.snap | 4 +- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/packages/excalidraw/actions/actionFinalize.tsx b/packages/excalidraw/actions/actionFinalize.tsx index cd640860af..a6a6fe63dd 100644 --- a/packages/excalidraw/actions/actionFinalize.tsx +++ b/packages/excalidraw/actions/actionFinalize.tsx @@ -41,7 +41,7 @@ export const actionFinalize = register({ const { interactiveCanvas, focusContainer, scene } = app; const elementsMap = scene.getNonDeletedElementsMap(); - console.log("actionFinalize"); + if (data?.event && appState.selectedLinearElement) { const linearElementEditor = LinearElementEditor.handlePointerUp( data.event, @@ -162,37 +162,38 @@ export const actionFinalize = register({ newElements = newElements.filter((el) => el.id !== element!.id); } - // If the multi point line closes the loop, - // set the last point to first point. - // This ensures that loop remains closed at different scales. - const isLoop = isPathALoop(element.points, appState.zoom.value); - if (element.type === "line" || element.type === "freedraw") { - if (isLoop) { - const linePoints = element.points; - const firstPoint = linePoints[0]; - scene.mutateElement(element, { - points: linePoints.map((p, index) => - index === linePoints.length - 1 - ? pointFrom(firstPoint[0], firstPoint[1]) - : p, - ), - }); + if (isLinearElement(element) || element.type === "freedraw") { + // If the multi point line closes the loop, + // set the last point to first point. + // This ensures that loop remains closed at different scales. + const isLoop = isPathALoop(element.points, appState.zoom.value); + if (element.type === "line" || element.type === "freedraw") { + if (isLoop) { + const linePoints = element.points; + const firstPoint = linePoints[0]; + scene.mutateElement(element, { + points: linePoints.map((p, index) => + index === linePoints.length - 1 + ? pointFrom(firstPoint[0], firstPoint[1]) + : p, + ), + }); + } } - } - if ( - isBindingElement(element) && - !isLoop && - element.points.length > 1 && - !appState.selectedElementIds[element.id] && - isBindingEnabled(appState) - ) { - const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates( - element, - -1, - arrayToMap(elements), - ); - maybeBindLinearElement(element, appState, { x, y }, scene); + if ( + isBindingElement(element) && + !isLoop && + element.points.length > 1 && + isBindingEnabled(appState) + ) { + const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates( + element, + -1, + arrayToMap(elements), + ); + maybeBindLinearElement(element, appState, { x, y }, scene); + } } } diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 8763045eb8..317ee0ad14 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -2925,28 +2925,6 @@ class App extends React.Component { this.setState({ selectedLinearElement: null }); } - const { multiElement } = prevState; - if ( - prevState.activeTool !== this.state.activeTool && - multiElement != null && - isBindingEnabled(this.state) && - isBindingElement(multiElement, false) - ) { - this.actionManager.executeAction(actionFinalize); - // maybeBindLinearElement( - // multiElement, - // this.state, - // tupleToCoors( - // LinearElementEditor.getPointAtIndexGlobalCoordinates( - // multiElement, - // -1, - // nonDeletedElementsMap, - // ), - // ), - // this.scene, - // ); - } - this.store.commit(elementsMap, this.state); // Do not notify consumers if we're still loading the scene. Among other diff --git a/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap index 5078a31a0e..39d04ab8c6 100644 --- a/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap @@ -173,7 +173,7 @@ exports[`move element > rectangles with binding arrow 6`] = ` "type": "rectangle", "updated": 1, "version": 7, - "versionNonce": 745419401, + "versionNonce": 1051383431, "width": 300, "x": 201, "y": 2, @@ -231,7 +231,7 @@ exports[`move element > rectangles with binding arrow 7`] = ` "type": "arrow", "updated": 1, "version": 11, - "versionNonce": 1051383431, + "versionNonce": 1996028265, "width": "86.85786", "x": "107.07107", "y": "47.07107",