diff --git a/src/element/textWysiwyg.tsx b/src/element/textWysiwyg.tsx index ffdc18cf..4edea15d 100644 --- a/src/element/textWysiwyg.tsx +++ b/src/element/textWysiwyg.tsx @@ -102,9 +102,11 @@ export const textWysiwyg = ({ const updateWysiwygStyle = () => { const appState = app.state; - const updatedElement = Scene.getScene(element)?.getElement( - id, - ) as ExcalidrawTextElement; + const updatedElement = + Scene.getScene(element)?.getElement(id); + if (!updatedElement) { + return; + } const { textAlign, verticalAlign } = updatedElement; const approxLineHeight = getApproxLineHeight(getFontString(updatedElement)); diff --git a/src/scene/Scene.ts b/src/scene/Scene.ts index 5d981c3f..4f05f52e 100644 --- a/src/scene/Scene.ts +++ b/src/scene/Scene.ts @@ -62,8 +62,8 @@ class Scene { return this.nonDeletedElements; } - getElement(id: ExcalidrawElement["id"]): ExcalidrawElement | null { - return this.elementsMap.get(id) || null; + getElement(id: T["id"]): T | null { + return (this.elementsMap.get(id) as T | undefined) || null; } getNonDeletedElement(