diff --git a/packages/element/src/__tests__/transform.test.ts b/packages/element/src/__tests__/transform.test.ts index b29dae1081..dd331a65ac 100644 --- a/packages/element/src/__tests__/transform.test.ts +++ b/packages/element/src/__tests__/transform.test.ts @@ -1293,4 +1293,47 @@ describe("Test Transform", () => { expect(frame.y).toBeLessThanOrEqual(minY); expect(frame.y + frame.height).toBeGreaterThanOrEqual(maxY); }); + + it("should place bound arrows listed by elements they aren't bound to", () => { + const convert = (stale: boolean) => + convertToExcalidrawElements( + [ + // lists the arrow without it being bound to it + ...(stale + ? [ + { + type: "rectangle" as const, + id: "X", + x: 0, + y: 300, + boundElements: [{ id: "arrow", type: "arrow" as const }], + }, + ] + : []), + { type: "rectangle", id: "A", x: 0, y: 0, width: 100, height: 100 }, + { type: "rectangle", id: "B", x: 400, y: 0, width: 100, height: 100 }, + { + type: "arrow", + id: "arrow", + x: 100, + y: 50, + points: [ + pointFrom(0, 0), + pointFrom(300, 0), + ], + start: { id: "A" }, + end: { id: "B" }, + }, + ], + opts, + ).find((element) => element.id === "arrow")!; + + const arrow = convert(true); + expect(arrow).toMatchObject({ + x: convert(false).x, + width: convert(false).width, + }); + // placed off A by the binding gap + expect(arrow.x).toBeGreaterThan(100); + }); }); diff --git a/packages/element/src/transform.ts b/packages/element/src/transform.ts index aa6539e312..1bfdf8d4cb 100644 --- a/packages/element/src/transform.ts +++ b/packages/element/src/transform.ts @@ -865,7 +865,13 @@ export const convertToExcalidrawElements = ( }); arrows.forEach(({ id }) => { const arrow = boundScene.getNonDeletedElement(id); - if (arrow) { + // only those actually bound to it, which it updated + if ( + arrow && + isArrowElement(arrow) && + (arrow.startBinding?.elementId === element.id || + arrow.endBinding?.elementId === element.id) + ) { updatedArrows.push(arrow); } });