Skip to content

Commit

Permalink
fix: updateWysiwygStyle updatedElement is undefined TypeError (excali…
Browse files Browse the repository at this point in the history
…draw#4980)

Co-authored-by: dwelle <[email protected]>
  • Loading branch information
zsviczian and dwelle authored Mar 27, 2022
1 parent 580e719 commit e940aeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/element/textWysiwyg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExcalidrawTextElement>(id);
if (!updatedElement) {
return;
}
const { textAlign, verticalAlign } = updatedElement;

const approxLineHeight = getApproxLineHeight(getFontString(updatedElement));
Expand Down
4 changes: 2 additions & 2 deletions src/scene/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Scene {
return this.nonDeletedElements;
}

getElement(id: ExcalidrawElement["id"]): ExcalidrawElement | null {
return this.elementsMap.get(id) || null;
getElement<T extends ExcalidrawElement>(id: T["id"]): T | null {
return (this.elementsMap.get(id) as T | undefined) || null;
}

getNonDeletedElement(
Expand Down

0 comments on commit e940aeb

Please sign in to comment.