mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-16 14:00:56 +02:00
feat: fit text to bound container
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user