From 807b3c59f2eae4b152142a54b5044e4cc485e579 Mon Sep 17 00:00:00 2001 From: Alplune Date: Sun, 26 Jan 2025 00:00:39 +0800 Subject: [PATCH] fix: align arrows bound to elements excalidraw#8833 (#8998) --- packages/excalidraw/actions/actionAlign.tsx | 1 + packages/excalidraw/align.ts | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/excalidraw/actions/actionAlign.tsx b/packages/excalidraw/actions/actionAlign.tsx index 6ebf6b7e7..ed078e9d5 100644 --- a/packages/excalidraw/actions/actionAlign.tsx +++ b/packages/excalidraw/actions/actionAlign.tsx @@ -48,6 +48,7 @@ const alignSelectedElements = ( selectedElements, elementsMap, alignment, + app.scene, ); const updatedElementsMap = arrayToMap(updatedElements); diff --git a/packages/excalidraw/align.ts b/packages/excalidraw/align.ts index 5abebea21..113ba274c 100644 --- a/packages/excalidraw/align.ts +++ b/packages/excalidraw/align.ts @@ -1,8 +1,10 @@ import type { ElementsMap, ExcalidrawElement } from "./element/types"; -import { newElementWith } from "./element/mutateElement"; +import { mutateElement } from "./element/mutateElement"; import type { BoundingBox } from "./element/bounds"; import { getCommonBoundingBox } from "./element/bounds"; import { getMaximumGroups } from "./groups"; +import { updateBoundElements } from "./element/binding"; +import type Scene from "./scene/Scene"; export interface Alignment { position: "start" | "center" | "end"; @@ -13,6 +15,7 @@ export const alignElements = ( selectedElements: ExcalidrawElement[], elementsMap: ElementsMap, alignment: Alignment, + scene: Scene, ): ExcalidrawElement[] => { const groups: ExcalidrawElement[][] = getMaximumGroups( selectedElements, @@ -26,12 +29,18 @@ export const alignElements = ( selectionBoundingBox, alignment, ); - return group.map((element) => - newElementWith(element, { + return group.map((element) => { + // update element + const updatedEle = mutateElement(element, { x: element.x + translation.x, y: element.y + translation.y, - }), - ); + }); + // update bound elements + updateBoundElements(element, scene.getNonDeletedElementsMap(), { + simultaneouslyUpdated: group, + }); + return updatedEle; + }); }); };