Skip to content

Commit 671b673

Browse files
committed
Add noRerender() function, as request in review
1 parent 96f6e30 commit 671b673

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

ts/ui/menu/Menu.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,14 +1181,14 @@ export class Menu {
11811181
protected setAssistiveMml(mml: boolean) {
11821182
this.document.options.enableAssistiveMml = mml;
11831183
if (mml) {
1184-
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
1185-
if (this.settings.speech) {
1186-
this.menu.pool.lookup('speech').setValue(false);
1187-
}
1188-
if (this.settings.braille) {
1189-
this.menu.pool.lookup('braille').setValue(false);
1190-
}
1191-
Menu.loading--;
1184+
this.noRerender(() => {
1185+
if (this.settings.speech) {
1186+
this.menu.pool.lookup('speech').setValue(false);
1187+
}
1188+
if (this.settings.braille) {
1189+
this.menu.pool.lookup('braille').setValue(false);
1190+
}
1191+
});
11921192
}
11931193
if (!mml || MathJax._?.a11y?.['assistive-mml']) {
11941194
this.rerender();
@@ -1224,9 +1224,7 @@ export class Menu {
12241224
this.enableAccessibilityItems('Speech', speech);
12251225
this.document.options.enableSpeech = speech;
12261226
if (speech && this.settings.assistiveMml) {
1227-
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
1228-
this.menu.pool.lookup('assistiveMml').setValue(false);
1229-
Menu.loading--;
1227+
this.noRerender(() => this.menu.pool.lookup('assistiveMml').setValue(false));
12301228
}
12311229
if (!speech || MathJax._?.a11y?.explorer) {
12321230
this.rerender(STATE.COMPILED);
@@ -1242,9 +1240,7 @@ export class Menu {
12421240
this.enableAccessibilityItems('Braille', braille);
12431241
this.document.options.enableBraille = braille;
12441242
if (braille && this.settings.assistiveMml) {
1245-
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
1246-
this.menu.pool.lookup('assistiveMml').setValue(false);
1247-
Menu.loading--;
1243+
this.noRerender(() => this.menu.pool.lookup('assistiveMml').setValue(false));
12481244
}
12491245
if (!braille || MathJax._?.a11y?.explorer) {
12501246
this.rerender(STATE.COMPILED);
@@ -1363,24 +1359,24 @@ export class Menu {
13631359
* Reset all menu settings to the (page) defaults
13641360
*/
13651361
protected resetDefaults() {
1366-
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
1367-
const pool = this.menu.pool;
1368-
const settings = this.defaultSettings;
1369-
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
1370-
const variable = pool.lookup(name);
1371-
if (variable) {
1372-
if (variable.getValue() !== settings[name]) {
1373-
variable.setValue(settings[name] as string | boolean);
1374-
const item = (variable as any).items[0];
1375-
if (item) {
1376-
item.executeCallbacks_();
1362+
this.noRerender(() => {
1363+
const pool = this.menu.pool;
1364+
const settings = this.defaultSettings;
1365+
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
1366+
const variable = pool.lookup(name);
1367+
if (variable) {
1368+
if (variable.getValue() !== settings[name]) {
1369+
variable.setValue(settings[name] as string | boolean);
1370+
const item = (variable as any).items[0];
1371+
if (item) {
1372+
item.executeCallbacks_();
1373+
}
13771374
}
1375+
} else if (Object.hasOwn(this.settings, name)) {
1376+
(this.settings as any)[name] = settings[name];
13781377
}
1379-
} else if (Object.hasOwn(this.settings, name)) {
1380-
(this.settings as any)[name] = settings[name];
13811378
}
1382-
}
1383-
Menu.loading--;
1379+
});
13841380
this.rerender(STATE.COMPILED);
13851381
}
13861382

@@ -1682,6 +1678,17 @@ export class Menu {
16821678
}
16831679
}
16841680

1681+
protected noRerender(exec: () => void) {
1682+
Menu.loading++; // pretend we're loading, to suppress rerendering durring exec() call
1683+
try {
1684+
exec();
1685+
Menu.loading--;
1686+
} catch(err) {
1687+
Menu.loading--; // make sure this resets if there is an error
1688+
throw err;
1689+
}
1690+
}
1691+
16851692
/**
16861693
* Copy the serialzied MathML to the clipboard
16871694
*/

0 commit comments

Comments
 (0)