Commit 86167a36 authored by Fred Chasen's avatar Fred Chasen

Fix for very long text nodes

parent 1ece4000
...@@ -370,7 +370,6 @@ class Chunker { ...@@ -370,7 +370,6 @@ class Chunker {
this.rendered = false; this.rendered = false;
this.q.enqueue(async () => { this.q.enqueue(async () => {
console.log("start",page.id, this.rendered);
this.start(); this.start();
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
isElement, isElement,
isText, isText,
indexOf, indexOf,
indexOfTextNode,
cloneNode, cloneNode,
findElement, findElement,
child, child,
...@@ -288,7 +289,7 @@ class Layout { ...@@ -288,7 +289,7 @@ class Layout {
} }
parent = findElement(renderedNode, source); parent = findElement(renderedNode, source);
index = indexOf(temp); index = indexOfTextNode(temp, parent);
node = child(parent, index); node = child(parent, index);
offset = 0; offset = 0;
} }
...@@ -300,8 +301,10 @@ class Layout { ...@@ -300,8 +301,10 @@ class Layout {
} }
parent = findElement(renderedNode, source); parent = findElement(renderedNode, source);
index = indexOf(container); index = indexOfTextNode(container, parent);
node = child(parent, index); node = child(parent, index);
offset += node.textContent.indexOf(container.textContent);
} }
if (!node) { if (!node) {
......
...@@ -509,3 +509,24 @@ export function hasTextContent(node) { ...@@ -509,3 +509,24 @@ export function hasTextContent(node) {
} }
return false; return false;
} }
export function indexOfTextNode(node, parent) {
if (!isText(node)) {
return -1;
}
let nodeTextContent = node.textContent;
let child;
let index = -1;
for (var i = 0; i < parent.childNodes.length; i++) {
child = parent.childNodes[i];
if (child.nodeType === 3) {
let text = parent.childNodes[i].textContent;
if (text.includes(nodeTextContent)) {
index = i;
break;
}
}
}
return index;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment