diff --git a/ts/handlers/html/HTMLDocument.ts b/ts/handlers/html/HTMLDocument.ts
index 385ffd584..cabdd1f74 100644
--- a/ts/handlers/html/HTMLDocument.ts
+++ b/ts/handlers/html/HTMLDocument.ts
@@ -124,14 +124,16 @@ export class HTMLDocument extends AbstractMathDocument {
nodes: HTMLNodeArray
): Location {
const adaptor = this.adaptor;
- for (const list of nodes[N]) {
- const [node, n] = list;
+ const inc = 1 / (nodes[N].length || 1);
+ let i = N;
+ for (const [node, n] of nodes[N]) {
if (index <= n && adaptor.kind(node) === '#text') {
- return { node: node, n: Math.max(index, 0), delim: delim };
+ return { i, node, n: Math.max(index, 0), delim };
}
index -= n;
+ i += inc;
}
- return { node: null, n: 0, delim: delim };
+ return { node: null, n: 0, delim };
}
/**