This commit is contained in:
Aakansha Doshi 2023-02-27 20:51:43 +05:30
parent 0a295e523b
commit 7722de4ef2

View File

@ -52,8 +52,6 @@ export const redrawTextBoundingBox = (
height: textElement.height, height: textElement.height,
}; };
boundTextUpdates.text = textElement.text;
if (container) { if (container) {
maxWidth = getMaxContainerWidth(container); maxWidth = getMaxContainerWidth(container);
boundTextUpdates.text = wrapText( boundTextUpdates.text = wrapText(
@ -62,6 +60,7 @@ export const redrawTextBoundingBox = (
maxWidth, maxWidth,
); );
} }
const metrics = measureText( const metrics = measureText(
boundTextUpdates.text, boundTextUpdates.text,
getFontString(textElement), getFontString(textElement),
@ -71,35 +70,26 @@ export const redrawTextBoundingBox = (
boundTextUpdates.height = metrics.height; boundTextUpdates.height = metrics.height;
if (container) { if (container) {
if (isArrowElement(container)) { const containerDims = getContainerDims(container);
const centerX = textElement.x + textElement.width / 2; const maxContainerHeight = getMaxContainerHeight(container);
const centerY = textElement.y + textElement.height / 2; let nextHeight = containerDims.height;
const diffWidth = metrics.width - textElement.width;
const diffHeight = metrics.height - textElement.height;
boundTextUpdates.x = centerY - (textElement.height + diffHeight) / 2;
boundTextUpdates.y = centerX - (textElement.width + diffWidth) / 2;
} else {
const containerDims = getContainerDims(container);
let maxContainerHeight = getMaxContainerHeight(container);
let nextHeight = containerDims.height; if (metrics.height > maxContainerHeight) {
if (metrics.height > maxContainerHeight) { nextHeight = computeContainerHeightForBoundText(
nextHeight = computeContainerHeightForBoundText( container,
container, metrics.height,
metrics.height, );
); mutateElement(container, { height: nextHeight });
mutateElement(container, { height: nextHeight }); updateOriginalContainerCache(container.id, nextHeight);
maxContainerHeight = getMaxContainerHeight(container);
updateOriginalContainerCache(container.id, nextHeight);
}
const updatedTextElement = {
...textElement,
...boundTextUpdates,
} as ExcalidrawTextElementWithContainer;
const { x, y } = computeBoundTextPosition(container, updatedTextElement);
boundTextUpdates.x = x;
boundTextUpdates.y = y;
} }
const updatedTextElement = {
...textElement,
...boundTextUpdates,
} as ExcalidrawTextElementWithContainer;
const { x, y } = computeBoundTextPosition(container, updatedTextElement);
boundTextUpdates.x = x;
boundTextUpdates.y = y;
} }
mutateElement(textElement, boundTextUpdates); mutateElement(textElement, boundTextUpdates);