fix: use cached width when calculating min width during resize (#4585)
This commit is contained in:
parent
1ef287027b
commit
dba71e358d
@ -36,6 +36,7 @@ import { Point, PointerDownState } from "../types";
|
||||
import Scene from "../scene/Scene";
|
||||
import {
|
||||
getApproxMinLineWidth,
|
||||
getBoundTextElement,
|
||||
getBoundTextElementId,
|
||||
handleBindTextResize,
|
||||
measureText,
|
||||
@ -588,15 +589,12 @@ export const resizeSingleElement = (
|
||||
});
|
||||
}
|
||||
let minWidth = 0;
|
||||
if (boundTextElementId) {
|
||||
const boundTextElement = Scene.getScene(element)!.getElement(
|
||||
boundTextElementId,
|
||||
) as ExcalidrawTextElement;
|
||||
const boundTextElement = getBoundTextElement(element);
|
||||
if (boundTextElement) {
|
||||
minWidth = getApproxMinLineWidth(getFontString(boundTextElement));
|
||||
}
|
||||
|
||||
if (
|
||||
resizedElement.width > minWidth &&
|
||||
resizedElement.width >= minWidth &&
|
||||
resizedElement.height !== 0 &&
|
||||
Number.isFinite(resizedElement.x) &&
|
||||
Number.isFinite(resizedElement.y)
|
||||
|
@ -362,10 +362,14 @@ export const charWidth = (() => {
|
||||
};
|
||||
})();
|
||||
export const getApproxMinLineWidth = (font: FontString) => {
|
||||
return (
|
||||
measureText(DUMMY_TEXT.split("").join("\n"), font).width +
|
||||
BOUND_TEXT_PADDING * 2
|
||||
);
|
||||
const minCharWidth = getMinCharWidth(font);
|
||||
if (minCharWidth === 0) {
|
||||
return (
|
||||
measureText(DUMMY_TEXT.split("").join("\n"), font).width +
|
||||
BOUND_TEXT_PADDING * 2
|
||||
);
|
||||
}
|
||||
return minCharWidth + BOUND_TEXT_PADDING * 2;
|
||||
};
|
||||
|
||||
export const getApproxMinLineHeight = (font: FontString) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user