Microsoft.Html.Core.Tree.Nodes.ElementNode.GetChildrenSurroundingRange C# (CSharp) Method

GetChildrenSurroundingRange() public method

Given text range locates previous and next child nodes that surround the range
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;
                }
            }
        }