fix: compute dimensions of container correctly when text pasted on container (#5845)

* fix: compute dimensions of container correctly when text pasted on container

* add test

* remove only
This commit is contained in:
Aakansha Doshi 2022-11-08 19:50:41 +05:30 committed by GitHub
parent e1c5c706c6
commit e201e79cd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 7 deletions

View file

@ -19,13 +19,12 @@ export const redrawTextBoundingBox = (
) => {
let maxWidth = undefined;
let text = textElement.text;
if (container) {
maxWidth = getMaxContainerWidth(container);
text = wrapText(
textElement.originalText,
getFontString(textElement),
getMaxContainerWidth(container),
maxWidth,
);
}
const metrics = measureText(
@ -230,10 +229,9 @@ export const measureText = (
const baseline = span.offsetTop + span.offsetHeight;
// Since span adds 1px extra width to the container
const width = container.offsetWidth + 1;
const height = container.offsetHeight;
document.body.removeChild(container);
document.body.removeChild(container);
return { width, height, baseline };
};