fix: set the dimensions of bound text correctly (#5710)

* fix: set the dimensions of bound text correctly

* use original Text when wrapping

* fix text align

* fix specs

* fix

* newline
This commit is contained in:
Aakansha Doshi 2022-09-22 15:40:38 +05:30 committed by GitHub
parent 8636ef1017
commit 4cb6f09559
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 57 deletions

View file

@ -252,8 +252,16 @@ const getAdjustedDimensions = (
};
};
export const getMaxContainerWidth = (container: ExcalidrawElement) => {
return getContainerDims(container).width - BOUND_TEXT_PADDING * 2;
};
export const getMaxContainerHeight = (container: ExcalidrawElement) => {
return getContainerDims(container).height - BOUND_TEXT_PADDING * 2;
};
export const updateTextElement = (
element: ExcalidrawTextElement,
textElement: ExcalidrawTextElement,
{
text,
isDeleted,
@ -264,16 +272,19 @@ export const updateTextElement = (
originalText: string;
},
): ExcalidrawTextElement => {
const container = getContainerElement(element);
const container = getContainerElement(textElement);
if (container) {
const containerDims = getContainerDims(container);
text = wrapText(text, getFontString(element), containerDims.width);
text = wrapText(
originalText,
getFontString(textElement),
getMaxContainerWidth(container),
);
}
const dimensions = getAdjustedDimensions(element, text);
return newElementWith(element, {
const dimensions = getAdjustedDimensions(textElement, text);
return newElementWith(textElement, {
text,
originalText,
isDeleted: isDeleted ?? element.isDeleted,
isDeleted: isDeleted ?? textElement.isDeleted,
...dimensions,
});
};