fix: Inform scenes of mutations when a subtype finishes loading.

This commit is contained in:
Daniel J. Geiger 2023-09-10 16:49:06 -05:00
parent 1bd86942f3
commit e0221ddf20

View File

@ -21,6 +21,7 @@ import {
redrawTextBoundingBox, redrawTextBoundingBox,
} from "./element/textElement"; } from "./element/textElement";
import { ShapeCache } from "./scene/ShapeCache"; import { ShapeCache } from "./scene/ShapeCache";
import Scene from "./scene/Scene";
// Use "let" instead of "const" so we can dynamically add subtypes // Use "let" instead of "const" so we can dynamically add subtypes
let subtypeNames: readonly Subtype[] = []; let subtypeNames: readonly Subtype[] = [];
@ -453,6 +454,7 @@ export const checkRefreshOnSubtypeLoad = (
elements: readonly ExcalidrawElement[], elements: readonly ExcalidrawElement[],
) => { ) => {
let refreshNeeded = false; let refreshNeeded = false;
const scenes: Scene[] = [];
getNonDeletedElements(elements).forEach((element) => { getNonDeletedElements(elements).forEach((element) => {
// If the element is of the subtype that was just // If the element is of the subtype that was just
// registered, update the element's dimensions, mark the // registered, update the element's dimensions, mark the
@ -463,7 +465,14 @@ export const checkRefreshOnSubtypeLoad = (
redrawTextBoundingBox(element, getContainerElement(element)); redrawTextBoundingBox(element, getContainerElement(element));
} }
refreshNeeded = true; refreshNeeded = true;
const scene = Scene.getScene(element);
if (scene && !scenes.includes(scene)) {
// Store in case we have multiple scenes
scenes.push(scene);
}
} }
}); });
// Only inform each scene once
scenes.forEach((scene) => scene.informMutation());
return refreshNeeded; return refreshNeeded;
}; };