Browse Source

floor line height and height when dom height increases than canvas height

Aakansha Doshi 2 years ago
parent
commit
8de6516823
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/element/textWysiwyg.tsx

+ 13 - 4
src/element/textWysiwyg.tsx

@@ -36,6 +36,7 @@ import {
   getMaxContainerWidth,
   computeContainerDimensionForBoundText,
   measureDOMHeight,
+  getLineHeightInPx,
   splitIntoLines,
 } from "./textElement";
 import {
@@ -278,11 +279,19 @@ export const textWysiwyg = ({
         getFontString(updatedTextElement),
         updatedTextElement.lineHeight,
       );
-
       let lineHeight = element.lineHeight;
-      if (isSafari && domHeight > textElementHeight) {
-        lineHeight = (Math.floor(element.lineHeight * element.fontSize) /
-          element.fontSize) as ExcalidrawTextElement["lineHeight"];
+      if (isSafari) {
+        const lineCount = splitIntoLines(element.text).length;
+        if (domHeight > textElementHeight) {
+          lineHeight = (Math.floor(element.lineHeight * element.fontSize) /
+            element.fontSize) as ExcalidrawTextElement["lineHeight"];
+          textElementHeight =
+            getLineHeightInPx(element.fontSize, lineHeight) * lineCount;
+          mutateElement(updatedTextElement, {
+            lineHeight,
+            height: textElementHeight,
+          });
+        }
       }
 
       // Make sure text editor height doesn't go beyond viewport