feat: fit text to bound container

This commit is contained in:
Ryan Di
2025-05-21 19:07:58 +10:00
parent 2a50000ec8
commit 6eb93b281a
2 changed files with 6 additions and 6 deletions

View File

@@ -366,15 +366,14 @@ export const adjustBoundTextSize = (
container: ExcalidrawTextContainer, container: ExcalidrawTextContainer,
boundText: ExcalidrawTextElementWithContainer, boundText: ExcalidrawTextElementWithContainer,
scene: Scene, scene: Scene,
wrapTextFirst = true,
) => { ) => {
const maxWidth = getBoundTextMaxWidth(container, boundText); const maxWidth = getBoundTextMaxWidth(container, boundText);
const maxHeight = getBoundTextMaxHeight(container, boundText); const maxHeight = getBoundTextMaxHeight(container, boundText);
const wrappedText = wrapText( const wrappedText = wrapTextFirst
boundText.text, ? wrapText(boundText.text, getFontString(boundText), maxWidth)
getFontString(boundText), : boundText.originalText;
maxWidth,
);
let metrics = measureText( let metrics = measureText(
wrappedText, wrappedText,

View File

@@ -62,6 +62,7 @@ import type {
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import type { MarkOptional } from "@excalidraw/common/utility-types"; import type { MarkOptional } from "@excalidraw/common/utility-types";
import { adjustBoundTextSize } from "../components/ConvertElementTypePopup";
export type ValidLinearElement = { export type ValidLinearElement = {
type: "arrow" | "line"; type: "arrow" | "line";
@@ -238,7 +239,7 @@ const bindTextToContainer = (
}), }),
}); });
redrawTextBoundingBox(textElement, container, scene); adjustBoundTextSize(container as any, textElement as any, scene, false);
return [container, textElement] as const; return [container, textElement] as const;
}; };