소스 검색

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

Daniel J. Geiger 2 년 전
부모
커밋
e0221ddf20
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      src/subtypes.ts

+ 9 - 0
src/subtypes.ts

@@ -21,6 +21,7 @@ import {
   redrawTextBoundingBox,
 } from "./element/textElement";
 import { ShapeCache } from "./scene/ShapeCache";
+import Scene from "./scene/Scene";
 
 // Use "let" instead of "const" so we can dynamically add subtypes
 let subtypeNames: readonly Subtype[] = [];
@@ -453,6 +454,7 @@ export const checkRefreshOnSubtypeLoad = (
   elements: readonly ExcalidrawElement[],
 ) => {
   let refreshNeeded = false;
+  const scenes: Scene[] = [];
   getNonDeletedElements(elements).forEach((element) => {
     // If the element is of the subtype that was just
     // registered, update the element's dimensions, mark the
@@ -463,7 +465,14 @@ export const checkRefreshOnSubtypeLoad = (
         redrawTextBoundingBox(element, getContainerElement(element));
       }
       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;
 };