diff --git a/packages/element/src/__tests__/transform.test.ts b/packages/element/src/__tests__/transform.test.ts index dd331a65ac..f1597ca69e 100644 --- a/packages/element/src/__tests__/transform.test.ts +++ b/packages/element/src/__tests__/transform.test.ts @@ -1294,6 +1294,36 @@ describe("Test Transform", () => { expect(frame.y + frame.height).toBeGreaterThanOrEqual(maxY); }); + it("should keep bound arrows sized by their points when labels rewrap", () => { + const elements = convertToExcalidrawElements( + [ + { type: "rectangle", id: "A", x: 0, y: 0, width: 100, height: 20 }, + { type: "rectangle", id: "B", x: 500, y: 0, width: 100, height: 20 }, + { + type: "arrow", + x: 100, + y: 10, + points: [pointFrom(0, 0), pointFrom(400, 0)], + start: { id: "A" }, + end: { id: "B" }, + // wraps to a taller label along the arrow shortened by its binding + label: { text: "aaaa bbbb cccc dddd eeee fff" }, + }, + ], + opts, + ); + const arrow = elements.find( + (element) => element.type === "arrow", + ) as ExcalidrawArrowElement; + const label = elements.find( + (element) => element.type === "text", + ) as ExcalidrawTextElement; + + expect(label.text).toContain("\n"); + expect(arrow.points.every(([, y]) => y === 0)).toBe(true); + expect(arrow.height).toBe(0); + }); + it("should place bound arrows listed by elements they aren't bound to", () => { const convert = (stale: boolean) => convertToExcalidrawElements( diff --git a/packages/element/src/textElement.ts b/packages/element/src/textElement.ts index 843b5d0f3a..297a716a17 100644 --- a/packages/element/src/textElement.ts +++ b/packages/element/src/textElement.ts @@ -218,8 +218,9 @@ export const handleBindTextResize = ( nextHeight = metrics.height; nextWidth = metrics.width; } - // increase height in case text element height exceeds - if (nextHeight > maxHeight) { + // increase height in case text element height exceeds (but not an + // arrow's, which its points determine, and its label doesn't grow) + if (!isArrowElement(container) && nextHeight > maxHeight) { containerHeight = computeContainerDimensionForBoundText( nextHeight, container.type, @@ -233,16 +234,15 @@ export const handleBindTextResize = ( scene.mutateElement(container, { height: containerHeight, - ...(!isArrowElement(container) && - getPositionAfterHeightChange( - container, - containerHeight, - shouldResizeFromCenter - ? "center" - : shouldResizeFromTop - ? "bottom" - : "top", - )), + ...getPositionAfterHeightChange( + container, + containerHeight, + shouldResizeFromCenter + ? "center" + : shouldResizeFromTop + ? "bottom" + : "top", + ), }); } diff --git a/packages/element/tests/linearElementEditor.test.tsx b/packages/element/tests/linearElementEditor.test.tsx index acbf649d42..144dff679d 100644 --- a/packages/element/tests/linearElementEditor.test.tsx +++ b/packages/element/tests/linearElementEditor.test.tsx @@ -1517,7 +1517,7 @@ describe("Test Linear Elements", () => { expect({ width: container.width, height: container.height }) .toMatchInlineSnapshot(` { - "height": 130, + "height": 0, "width": 340, } `);