public GetChildrenSurroundingRange ( ITextRange range, int &child1, int &child2 ) : void | ||
range | ITextRange | Text range |
child1 | int | Index of the child node that precedes start of the range |
child2 | int | Index of the child that follows end of the range |
return | void |
public void GetChildrenSurroundingRange(ITextRange range, out int child1, out int child2) {
child1 = -1;
child2 = -1;
// Linear search (can be made binary since children are normally sorted).
// However, typically there are not that many of them to look through.
for (int i = Children.Count - 1; i >= 0; i--) {
if (Children[i].End <= range.Start) {
child1 = i;
break;
}
}
for (int i = child1 + 1; i < Children.Count; i++) {
if (Children[i].Start >= range.End) {
child2 = i;
break;
}
}
}