Commit 66c1ae1b authored by Fred Chasen's avatar Fred Chasen

Merge branch 'long_textnode_fixes' into 'master'

Fix for very long text nodes

See merge request tools/pagedjs!39
parents 1ece4000 86167a36
......@@ -370,7 +370,6 @@ class Chunker {
this.rendered = false;
this.q.enqueue(async () => {
console.log("start",page.id, this.rendered);
this.start();
......
......@@ -13,6 +13,7 @@ import {
isElement,
isText,
indexOf,
indexOfTextNode,
cloneNode,
findElement,
child,
......@@ -288,7 +289,7 @@ class Layout {
}
parent = findElement(renderedNode, source);
index = indexOf(temp);
index = indexOfTextNode(temp, parent);
node = child(parent, index);
offset = 0;
}
......@@ -300,8 +301,10 @@ class Layout {
}
parent = findElement(renderedNode, source);
index = indexOf(container);
index = indexOfTextNode(container, parent);
node = child(parent, index);
offset += node.textContent.indexOf(container.textContent);
}
if (!node) {
......
......@@ -509,3 +509,24 @@ export function hasTextContent(node) {
}
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