fix: stuck resizing when resizing bound text container very fast beyond threshold (#4804)

* fix: stuck resizing when resizing bound text container very fast beyond threshold

* fix

* fix
This commit is contained in:
Aakansha Doshi 2022-02-18 18:20:55 +05:30 committed by GitHub
parent 0896892f8a
commit 4604c8d823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 16 deletions

View file

@ -144,6 +144,7 @@ export const handleBindTextResize = (
}
const updatedY = element.y + containerHeight / 2 - nextHeight / 2;
mutateElement(textElement, {
text,
// preserve padding and set width correctly
@ -355,6 +356,7 @@ export const charWidth = (() => {
const width = getTextWidth(char, font);
cachedCharWidth[font][ascii] = width;
}
return cachedCharWidth[font][ascii];
};
@ -367,14 +369,14 @@ export const charWidth = (() => {
};
})();
export const getApproxMinLineWidth = (font: FontString) => {
const minCharWidth = getMinCharWidth(font);
if (minCharWidth === 0) {
const maxCharWidth = getMaxCharWidth(font);
if (maxCharWidth === 0) {
return (
measureText(DUMMY_TEXT.split("").join("\n"), font).width +
BOUND_TEXT_PADDING * 2
);
}
return minCharWidth + BOUND_TEXT_PADDING * 2;
return maxCharWidth + BOUND_TEXT_PADDING * 2;
};
export const getApproxMinLineHeight = (font: FontString) => {
@ -391,6 +393,15 @@ export const getMinCharWidth = (font: FontString) => {
return Math.min(...cacheWithOutEmpty);
};
export const getMaxCharWidth = (font: FontString) => {
const cache = charWidth.getCache(font);
if (!cache) {
return 0;
}
const cacheWithOutEmpty = cache.filter((val) => val !== undefined);
return Math.max(...cacheWithOutEmpty);
};
export const getApproxCharsToFitInWidth = (font: FontString, width: number) => {
// Generally lower case is used so converting to lower case
const dummyText = DUMMY_TEXT.toLocaleLowerCase();