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 Scene from "../scene/Scene";
|
||||||
import {
|
import {
|
||||||
getApproxMinLineWidth,
|
getApproxMinLineWidth,
|
||||||
|
getBoundTextElement,
|
||||||
getBoundTextElementId,
|
getBoundTextElementId,
|
||||||
handleBindTextResize,
|
handleBindTextResize,
|
||||||
measureText,
|
measureText,
|
||||||
@ -588,15 +589,12 @@ export const resizeSingleElement = (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
let minWidth = 0;
|
let minWidth = 0;
|
||||||
if (boundTextElementId) {
|
const boundTextElement = getBoundTextElement(element);
|
||||||
const boundTextElement = Scene.getScene(element)!.getElement(
|
if (boundTextElement) {
|
||||||
boundTextElementId,
|
|
||||||
) as ExcalidrawTextElement;
|
|
||||||
minWidth = getApproxMinLineWidth(getFontString(boundTextElement));
|
minWidth = getApproxMinLineWidth(getFontString(boundTextElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
resizedElement.width > minWidth &&
|
resizedElement.width >= minWidth &&
|
||||||
resizedElement.height !== 0 &&
|
resizedElement.height !== 0 &&
|
||||||
Number.isFinite(resizedElement.x) &&
|
Number.isFinite(resizedElement.x) &&
|
||||||
Number.isFinite(resizedElement.y)
|
Number.isFinite(resizedElement.y)
|
||||||
|
@ -362,10 +362,14 @@ export const charWidth = (() => {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
export const getApproxMinLineWidth = (font: FontString) => {
|
export const getApproxMinLineWidth = (font: FontString) => {
|
||||||
return (
|
const minCharWidth = getMinCharWidth(font);
|
||||||
measureText(DUMMY_TEXT.split("").join("\n"), font).width +
|
if (minCharWidth === 0) {
|
||||||
BOUND_TEXT_PADDING * 2
|
return (
|
||||||
);
|
measureText(DUMMY_TEXT.split("").join("\n"), font).width +
|
||||||
|
BOUND_TEXT_PADDING * 2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return minCharWidth + BOUND_TEXT_PADDING * 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getApproxMinLineHeight = (font: FontString) => {
|
export const getApproxMinLineHeight = (font: FontString) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user