fix: updateWysiwygStyle updatedElement is undefined TypeError (#4980)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
zsviczian 2022-03-28 00:14:04 +02:00 committed by GitHub
parent 580e719580
commit e940aeb1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -102,9 +102,11 @@ export const textWysiwyg = ({
const updateWysiwygStyle = () => { const updateWysiwygStyle = () => {
const appState = app.state; const appState = app.state;
const updatedElement = Scene.getScene(element)?.getElement( const updatedElement =
id, Scene.getScene(element)?.getElement<ExcalidrawTextElement>(id);
) as ExcalidrawTextElement; if (!updatedElement) {
return;
}
const { textAlign, verticalAlign } = updatedElement; const { textAlign, verticalAlign } = updatedElement;
const approxLineHeight = getApproxLineHeight(getFontString(updatedElement)); const approxLineHeight = getApproxLineHeight(getFontString(updatedElement));

View File

@ -62,8 +62,8 @@ class Scene {
return this.nonDeletedElements; return this.nonDeletedElements;
} }
getElement(id: ExcalidrawElement["id"]): ExcalidrawElement | null { getElement<T extends ExcalidrawElement>(id: T["id"]): T | null {
return this.elementsMap.get(id) || null; return (this.elementsMap.get(id) as T | undefined) || null;
} }
getNonDeletedElement( getNonDeletedElement(