mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-11-29 16:40:40 +03:00
fix(element): don't grow arrow height to fit rewrapped labels
Review finding 1. The skeleton placement pass in convertToExcalidrawElements() calls updateBoundElements(), which calls handleBindTextResize() for arrows with labels. When the label rewraps taller than getBoundTextMaxHeight() allows (for arrows under 80px tall, that is the label's old height), it set the arrow's `height` from the text, leaving it inconsistent with its points. Reproduction steps: convertToExcalidrawElements() with rectangles A (0,0,100x20) and B (500,0,100x20), an arrow at (100,10) with points [[0,0],[400,0]] bound from A to B with label "aaaa bbbb cccc dddd eeee fff", and a frame containing all three. Placement shortens the arrow, so the label wraps to 2 lines (height 25 -> 50). Failure case: observed arrow height 130 (50 + 80 padding) with points [[0,0],[388,0]]; expected 0, as the points are horizontal. The stale height persists through updateScene() and inflates later getBoundTextMaxHeight() results. The same happens in the editor: dragging the end point of a horizontal labelled arrow (linearElementEditor.test.tsx) left it at height 130. Fix: handleBindTextResize() no longer grows arrow containers to fit their label, matching redrawTextBoundingBox(), which already exempts arrows: an arrow's size derives from its points, and its label is positioned along them rather than within its height. The label itself still rewraps. The linearElementEditor inline snapshot that recorded the bogus height of 130 for a horizontal arrow is updated to 0.
This commit is contained in:
3 files changed
+43
-13
No files matched your search
@@ -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<LocalPoint>(0, 0), pointFrom<LocalPoint>(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(
|
||||
|
||||
@@ -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",
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1517,7 +1517,7 @@ describe("Test Linear Elements", () => {
|
||||
expect({ width: container.width, height: container.height })
|
||||
.toMatchInlineSnapshot(`
|
||||
{
|
||||
"height": 130,
|
||||
"height": 0,
|
||||
"width": 340,
|
||||
}
|
||||
`);
|
||||
|
||||
Reference in new issue
Block a user