}
private Builder deleteRangeInternal(int startLocation, int endLocation) {
// TODO(danilatos): Delete this method when deleting is redone efficiently
Builder builder = at(startLocation);
Point<N> start = doc.locate(startLocation);
Point<N> end = doc.locate(endLocation);
assert doc.isSameNode(
Point.enclosingElement(doc, start.getContainer()),
Point.enclosingElement(doc, end.getContainer()))
: "Range must be within a single element";
N node;
if (start.isInTextNode()) {
if (doc.isSameNode(start.getContainer(), end.getContainer())) {
int size = end.getTextOffset() - start.getTextOffset();
if (size > 0) {
builder.deleteCharacters(size);
}
return builder;
} else {
int size = doc.getLength(doc.asText(start.getContainer())) - start.getTextOffset();
node = doc.getNextSibling(start.getContainer());
if (size > 0) {
builder.deleteCharacters(size);
}
}
} else {
node = start.getNodeAfter();
}
N stop;
if (end.isInTextNode()) {
stop = end.getContainer();
} else {
stop = end.getNodeAfter();
}
while (node != stop) {
N next = doc.getNextSibling(node);
T text = doc.asText(node);
if (text != null) {
builder.deleteCharacters(doc.getData(text).length());
} else {
deleteElement(doc.asElement(node), builder);
}
node = next;
}
if (end.isInTextNode()) {
int size = end.getTextOffset();
if (size > 0) {
builder.deleteCharacters(size);
}
}
return builder;
}