Răsfoiți Sursa

Merge pull request #31937 from overleaf/mj-cache-equation-height

[web] Cache equation height in visual editor

GitOrigin-RevId: d10c65a904d6d803f1cf006c18ee69b88ec66210
Mathias Jakobsen 5 luni în urmă
părinte
comite
8c7fe88c8c

+ 3 - 1
services/web/frontend/js/features/source-editor/extensions/visual/visual-widgets/math.ts

@@ -4,6 +4,7 @@ import { placeSelectionInsideBlock } from '../selection'
 
 export class MathWidget extends WidgetType {
   destroyed = false
+  cachedHeight: number | undefined = undefined
 
   constructor(
     public math: string,
@@ -76,7 +77,7 @@ export class MathWidget extends WidgetType {
   }
 
   get estimatedHeight() {
-    return this.math.split('\n').length * 40
+    return this.cachedHeight ?? this.math.split('\n').length * 40
   }
 
   coordsAt(element: HTMLElement) {
@@ -111,5 +112,6 @@ export class MathWidget extends WidgetType {
     })
     element.replaceChildren(math)
     element.style.height = 'auto'
+    this.cachedHeight = element.offsetHeight
   }
 }