diff --git a/src/element/resizeElements.ts b/src/element/resizeElements.ts index 40a01f55..e925b0e2 100644 --- a/src/element/resizeElements.ts +++ b/src/element/resizeElements.ts @@ -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) diff --git a/src/element/textElement.ts b/src/element/textElement.ts index 2e3bbb4d..efe799a9 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -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) => {