Skip to content

Commit 0cea67e

Browse files
committed
Fix unhighlighting foreground colors in SVG, and copy the parts array so the cached array is not modified when the enclosure is added
1 parent 3370290 commit 0cea67e

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ts/a11y/explorer/Highlighter.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,28 @@ class SvgHighlighter extends AbstractHighlighter {
467467
*/
468468
public unhighlightNode(info: Highlight) {
469469
const node = info.node;
470-
const previous = node.previousSibling as HTMLElement;
471470
if (node.hasAttribute('data-sre-highlighter-bbox')) {
472471
node.remove();
473472
return;
474473
}
475-
node.removeAttribute('data-mjx-enclosed');
476-
if (previous && previous.hasAttribute('data-sre-highlighter-added')) {
477-
info.foreground
478-
? node.setAttribute('fill', info.foreground)
479-
: node.removeAttribute('fill');
480-
previous.remove();
474+
if (node.tagName === 'svg' || node.tagName === 'MJX-CONTAINER') {
475+
if (!node.hasAttribute('data-mjx-enclosed')) {
476+
node.style.backgroundColor = info.background;
477+
}
478+
node.removeAttribute('data-mjx-enclosed');
479+
node.style.color = info.foreground;
481480
return;
482481
}
483-
node.style.backgroundColor = info.background;
484-
node.style.color = info.foreground;
482+
const previous = node.previousSibling as HTMLElement;
483+
if (previous?.hasAttribute('data-sre-highlighter-added')) {
484+
previous.remove();
485+
}
486+
node.removeAttribute('data-mjx-enclosed');
487+
if (info.foreground) {
488+
node.setAttribute('fill', info.foreground);
489+
} else {
490+
node.removeAttribute('fill');
491+
}
485492
}
486493

487494
/**

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ export class SpeechExplorer
10231023
this.current = node;
10241024
this.currentMark = -1;
10251025
if (this.current) {
1026-
const parts = this.getSplitNodes(this.current);
1026+
const parts = [...this.getSplitNodes(this.current)];
10271027
this.highlighter.encloseNodes(parts, this.node);
10281028
for (const part of parts) {
10291029
if (!part.getAttribute('data-mjx-enclosed')) {

0 commit comments

Comments
 (0)