Browse Source

fix: 4d6d6cf1 had a line-height regression for sufficiently short math symbols

Daniel J. Geiger 1 year ago
parent
commit
7225915b82

+ 1 - 1
src/element/subtypes/mathjax/implementation.tsx

@@ -668,7 +668,7 @@ const measureMarkup = (
   }
   document.body.removeChild(container);
   let width = 0;
-  let height = 0;
+  let height = measureText(" ", font, lineHeight).height;
   childMetrics.forEach((metrics) => (width += metrics.width));
   childMetrics.forEach(
     (metrics) => (height = Math.max(height, metrics.height)),

+ 26 - 0
src/element/subtypes/mathjax/tests/implementation.test.tsx

@@ -18,4 +18,30 @@ describe("mathjax", () => {
     const metrics2 = measureTextElement(elements[1]);
     expect(metrics1).toStrictEqual(metrics2);
   });
+  it("minimum height remains", async () => {
+    await render(<ExcalidrawApp />);
+    await ensureSubtypesLoaded(["math"]);
+    const elements = [
+      API.createElement({ type: "text", id: "A", text: "a" }),
+      API.createElement({
+        type: "text",
+        id: "B",
+        text: "\\(\\alpha\\)",
+        subtype: "math",
+        customData: { useTex: true },
+      }),
+      API.createElement({
+        type: "text",
+        id: "C",
+        text: "`beta`",
+        subtype: "math",
+        customData: { useTex: false },
+      }),
+    ];
+    const height = measureTextElement(elements[0]).height;
+    const height1 = measureTextElement(elements[1]).height;
+    const height2 = measureTextElement(elements[2]).height;
+    expect(height).toEqual(height1);
+    expect(height).toEqual(height2);
+  });
 });