Skip to content

Commit 272b84c

Browse files
authored
Fix oppia#22065: Ensure MathExpressionEditor Displays Previous Content Correctly (oppia#22154)
able to edit the contents of previousforumla in editor
1 parent e731195 commit 272b84c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

extensions/objects/templates/math-expression-content-editor.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export class MathExpressionContentEditorComponent implements OnInit {
8282

8383
ngOnInit(): void {
8484
this.insertScriptService.loadScript(KNOWN_SCRIPTS.MATHJAX, () => {
85-
this.init();
85+
MathJax.Hub.Queue(() => {
86+
this.init();
87+
});
8688
});
8789
}
8890

@@ -149,8 +151,12 @@ export class MathExpressionContentEditorComponent implements OnInit {
149151
outputElement.innerHTML = s.outerHTML;
150152
// Naturally MathJax works asynchronously, but we can add processes
151153
// which we want to happen synchronously into the MathJax Hub Queue.
154+
this.numberOfElementsInQueue = Math.max(
155+
0,
156+
this.numberOfElementsInQueue + 1
157+
);
152158
MathJax.Hub.Queue(['Typeset', MathJax.Hub, outputElement]);
153-
this.numberOfElementsInQueue++;
159+
154160
MathJax.Hub.Queue(() => {
155161
if (outputElement.getElementsByTagName('svg')[0] !== undefined) {
156162
let svgElement = outputElement.getElementsByTagName('svg')[0];
@@ -163,7 +169,11 @@ export class MathExpressionContentEditorComponent implements OnInit {
163169
svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
164170
this.svgString = svgElement.outerHTML;
165171
}
166-
this.numberOfElementsInQueue--;
172+
this.numberOfElementsInQueue = Math.max(
173+
0,
174+
this.numberOfElementsInQueue - 1
175+
);
176+
167177
// We need to ensure that all the typepsetting requests in the
168178
// MathJax queue is finished before we save the final SVG.
169179
if (this.numberOfElementsInQueue === 0) {

0 commit comments

Comments
 (0)