JsTextRangeIE attempt = JsTextRangeIE.create();
int low = 0;
int high = parent.getChildCount() - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
Node node = parent.getChild(mid);
node.getParentNode().insertBefore(setter, node);
attempt.moveToElementText(setter).collapse(false);
int cmp = attempt.compareEndPoints(CompareMode.StartToEnd, target);
if (cmp == 0) {
if (DomHelper.isTextNode(node)) {
return Point.inText(node, 0);
} else {
return Point.inElement(parent, node);
}
} else if (cmp > 0) {
high = mid - 1;
} else {
if (DomHelper.isTextNode(node)) {
JsTextRangeIE dup = attempt.duplicate();
dup.setEndPoint(EndToEnd, target);
if (dup.getText().length() <= node.<Text> cast().getLength()) {
return Point.inText(node, dup.getText().length());
}
} else {
attempt.moveToElementText(node.<Element> cast()).collapse(false);
if (attempt.compareEndPoints(StartToStart, target) >= 0) {
return Point.inElement(parent, node);
}
}