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

[web] Cache equation height in visual editor

GitOrigin-RevId: d10c65a904d6d803f1cf006c18ee69b88ec66210
This commit is contained in:
Mathias Jakobsen
2026-03-03 12:12:49 +00:00
committed by Copybot
parent bb3e1286db
commit 8c7fe88c8c

View File

@@ -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
}
}