Skip to content

Commit 10a5ec8

Browse files
authored
Merge pull request #1082 from mathjax/menu-fixes
Menu fixes
2 parents 876c8a6 + 3801c54 commit 10a5ec8

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

ts/ui/menu/Menu.ts

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export class Menu {
498498
this.a11yVar<boolean>('speech', speech => this.setSpeech(speech)),
499499
this.a11yVar<boolean>('braille', braille => this.setBraille(braille)),
500500
this.variable<string>('brailleCode', code => this.setBrailleCode(code)),
501-
this.a11yVar<string> ('highlight'),
501+
this.a11yVar<string> ('highlight', value => this.setHighlight(value)),
502502
this.a11yVar<string> ('backgroundColor'),
503503
this.a11yVar<string> ('backgroundOpacity'),
504504
this.a11yVar<string> ('foregroundColor'),
@@ -507,20 +507,12 @@ export class Menu {
507507
this.a11yVar<boolean>('viewBraille'),
508508
this.a11yVar<boolean>('voicing'),
509509
this.a11yVar<string>('locale', locale => this.setLocale(locale)),
510-
{
511-
name: 'speechRules',
512-
getter: () => {
513-
return this.settings['speechRules'];
514-
},
515-
setter: (value: string) => {
516-
const [domain, style] = value.split('-');
517-
this.settings['speechRules'] = value;
518-
this.document.options.sre.domain = domain;
519-
this.document.options.sre.style = style;
520-
this.rerender(STATE.COMPILED);
521-
this.saveUserSettings();
522-
}
523-
},
510+
this.variable<string>('speechRules', value => {
511+
const [domain, style] = value.split('-');
512+
this.document.options.sre.domain = domain;
513+
this.document.options.sre.style = style;
514+
this.rerender(STATE.COMPILED);
515+
}),
524516
this.a11yVar<string> ('magnification'),
525517
this.a11yVar<string> ('magnify'),
526518
this.a11yVar<boolean>('treeColoring'),
@@ -684,9 +676,6 @@ export class Menu {
684676
menu.setJax(this.jax);
685677
this.attachDialogMenus(menu);
686678
this.checkLoadableItems();
687-
this.enableAccessibilityItems('Speech', this.settings.speech);
688-
this.enableAccessibilityItems('Braille', this.settings.braille);
689-
this.setAccessibilityMenus();
690679
const cache: [string, string][] = [];
691680
MJContextMenu.DynamicSubmenus.set(
692681
'ShowAnnotation',
@@ -832,9 +821,9 @@ export class Menu {
832821
this.setTabOrder(this.settings.inTabOrder);
833822
const options = this.document.options;
834823
options.enableAssistiveMml = this.settings.assistiveMml;
835-
options.enableSpeech = this.settings.speech;
836-
options.enableBraille = this.settings.braille;
837-
options.enableExplorer = this.settings.enrich;
824+
this.enableAccessibilityItems('Speech', this.settings.speech);
825+
this.enableAccessibilityItems('Braille', this.settings.braille);
826+
this.setAccessibilityMenus();
838827
const renderer = this.settings.renderer.replace(/[^a-zA-Z0-9]/g, '') || 'CHTML';
839828
const promise = (Menu._loadingPromise || Promise.resolve()).then(
840829
() => (renderer !== this.defaultSettings.renderer ?
@@ -949,6 +938,8 @@ export class Menu {
949938
const enable = this.settings.enrich;
950939
const method = (enable ? 'enable' : 'disable');
951940
['Speech', 'Braille', 'Explorer'].forEach(id => this.menu.findID(id)[method]());
941+
const options = this.document.options;
942+
options.enableSpeech = options.enableBraille = options.enableExplorer = enable;
952943
if (!enable) {
953944
this.settings.collapsible = false;
954945
this.document.options.enableCollapsible = false;
@@ -1001,7 +992,7 @@ export class Menu {
1001992
* @param {boolean} enrich True to enable enriched math, false to not
1002993
*/
1003994
protected setEnrichment(enrich: boolean) {
1004-
this.document.options.enableEnrichment = this.document.options.enableExplorer = enrich;
995+
this.document.options.enableEnrichment = enrich;
1005996
this.setAccessibilityMenus();
1006997
if (!enrich || MathJax._?.a11y?.['semantic-enrich']) {
1007998
this.rerender(STATE.COMPILED);
@@ -1016,8 +1007,11 @@ export class Menu {
10161007
protected setCollapsible(collapse: boolean) {
10171008
this.document.options.enableComplexity = collapse;
10181009
if (collapse && !this.settings.enrich) {
1019-
this.settings.enrich = true;
1020-
this.setEnrichment(true);
1010+
this.settings.enrich = this.document.options.enableEnrichment = true;
1011+
this.setAccessibilityMenus();
1012+
}
1013+
if (!collapse) {
1014+
this.menu.pool.lookup('highlight').setValue('None');
10211015
}
10221016
if (!collapse || MathJax._?.a11y?.complexity) {
10231017
this.rerender(STATE.COMPILED);
@@ -1029,6 +1023,21 @@ export class Menu {
10291023
}
10301024
}
10311025

1026+
/**
1027+
* @param {string} value The value that highlighting should have
1028+
*/
1029+
protected setHighlight(value: string) {
1030+
if (value === 'None') return;
1031+
if (!this.settings.collapsible) {
1032+
//
1033+
// Turn on collapsible math if it isn't already
1034+
//
1035+
const variable = this.menu.pool.lookup('collapsible');
1036+
variable.setValue(true);
1037+
(variable as any).items[0]?.executeCallbacks_?.();
1038+
}
1039+
}
1040+
10321041
/**
10331042
* Request the scaling value from the user and save it in the settings
10341043
*/

0 commit comments

Comments
 (0)