Преглед изворни кода

fix: stale labeled arrow bounds cache after editing the label (#6893)

* fix stale labeled arrow bounds cache after editing the label

* add arrow bounds test

* fix test to check the arrow version

* fix

* fix test - remove unused import

* Update src/element/textWysiwyg.test.tsx

---------

Co-authored-by: Aakansha Doshi <[email protected]>
Alex Kim пре 1 година
родитељ
комит
5191cdbe26
2 измењених фајлова са 30 додато и 1 уклоњено
  1. 26 0
      src/element/textWysiwyg.test.tsx
  2. 4 1
      src/element/textWysiwyg.tsx

+ 26 - 0
src/element/textWysiwyg.test.tsx

@@ -1509,4 +1509,30 @@ describe("textWysiwyg", () => {
       expect(text.text).toBe("Excalidraw");
     });
   });
+
+  it("should bump the version of labelled arrow when label updated", async () => {
+    await render(<ExcalidrawApp />);
+    const arrow = UI.createElement("arrow", {
+      width: 300,
+      height: 0,
+    });
+
+    mouse.select(arrow);
+    Keyboard.keyPress(KEYS.ENTER);
+    let editor = getTextEditor();
+    await new Promise((r) => setTimeout(r, 0));
+    updateTextEditor(editor, "Hello");
+    editor.blur();
+
+    const { version } = arrow;
+
+    mouse.select(arrow);
+    Keyboard.keyPress(KEYS.ENTER);
+    editor = getTextEditor();
+    await new Promise((r) => setTimeout(r, 0));
+    updateTextEditor(editor, "Hello\nworld!");
+    editor.blur();
+
+    expect(arrow.version).toEqual(version + 1);
+  });
 });

+ 4 - 1
src/element/textWysiwyg.tsx

@@ -20,7 +20,7 @@ import {
   ExcalidrawTextContainer,
 } from "./types";
 import { AppState } from "../types";
-import { mutateElement } from "./mutateElement";
+import { bumpVersion, mutateElement } from "./mutateElement";
 import {
   getBoundTextElementId,
   getContainerElement,
@@ -541,6 +541,9 @@ export const textWysiwyg = ({
               id: element.id,
             }),
           });
+        } else if (isArrowElement(container)) {
+          // updating an arrow label may change bounds, prevent stale cache:
+          bumpVersion(container);
         }
       } else {
         mutateElement(container, {