EditorStaticDeps.startIgnoreMutations();
try {
boolean ret = false;
ContentView renderedContent = getRenderedContentView();
HtmlView filteredHtml = getFilteredHtmlView();
ContentNode node = from;
Node nodelet;
if (node == null) {
node = renderedContent.getFirstChild(this);
nodelet = filteredHtml.getFirstChild(getImplNodelet());
} else {
nodelet = node.getImplNodelet();
}
while (node != null) {
if (node.getImplNodelet() != nodelet) {
node.setImplNodelet(nodelet);
}
if (DomHelper.isTextNode(nodelet)) {
String target = ((ContentTextNode) node).getData();
String txt = nodelet.<Text>cast().getData();
String nodeletData = txt;
int left = target.length() - txt.length();
while (left > 0) {
nodelet = filteredHtml.getNextSibling(nodelet);
assert DomHelper.isTextNode(nodelet) : "Some random element!";
nodeletData = nodelet.<Text>cast().getData();
// TODO(danilatos): Is a StringBuilder more efficient here? On average, how many
// string concatenations are expected?
txt += nodeletData;
left -= nodeletData.length();
}
assert target.equals(ContentTextNode.getNodeValueFromHtmlString(
txt.substring(0, target.length()))) : "Content & html text don't match!";
if (left < 0) {
if (nodelet.equals(notifyIfSplit)) {
ret = true;
}
nodelet.<Text>cast().splitText(nodeletData.length() + left);
}
}
nodelet = filteredHtml.getNextSibling(nodelet);
node = renderedContent.getNextSibling(node);
if (node == to) {
break;
}