Exemple #1
0
        // Token: 0x06003DB0 RID: 15792 RVA: 0x0011C904 File Offset: 0x0011AB04
        internal static void Remove(TextTreeTextBlock firstNode, TextTreeTextBlock lastNode)
        {
            SplayTreeNode previousNode = firstNode.GetPreviousNode();
            SplayTreeNode splayTreeNode;

            if (previousNode != null)
            {
                previousNode.Split();
                splayTreeNode           = previousNode.ParentNode;
                previousNode.ParentNode = null;
            }
            else
            {
                splayTreeNode = firstNode.GetContainingNode();
            }
            SplayTreeNode rightSubTree   = lastNode.Split();
            SplayTreeNode splayTreeNode2 = SplayTreeNode.Join(previousNode, rightSubTree);

            if (splayTreeNode != null)
            {
                splayTreeNode.ContainedNode = splayTreeNode2;
            }
            if (splayTreeNode2 != null)
            {
                splayTreeNode2.ParentNode = splayTreeNode;
            }
        }
        // Token: 0x060035C4 RID: 13764 RVA: 0x000F44EC File Offset: 0x000F26EC
        internal void InsertAtNode(SplayTreeNode location, bool insertBefore)
        {
            Invariant.Assert(this.ParentNode == null, "Can't insert child node!");
            Invariant.Assert(this.LeftChildNode == null, "Can't insert node with left children!");
            Invariant.Assert(this.RightChildNode == null, "Can't insert node with right children!");
            SplayTreeNode splayTreeNode = insertBefore ? location.GetPreviousNode() : location;
            SplayTreeNode rightSubTree;
            SplayTreeNode parentNode;

            if (splayTreeNode != null)
            {
                rightSubTree = splayTreeNode.Split();
                parentNode   = splayTreeNode.ParentNode;
            }
            else
            {
                rightSubTree = location;
                location.Splay();
                Invariant.Assert(location.Role == SplayTreeNodeRole.LocalRoot, "location should be local root!");
                parentNode = location.ParentNode;
            }
            SplayTreeNode.Join(this, splayTreeNode, rightSubTree);
            this.ParentNode = parentNode;
            if (parentNode != null)
            {
                parentNode.ContainedNode = this;
            }
        }
Exemple #3
0
        // Splits a sibling tree into three sub trees -- a tree with content before startPosition,
        // a tree with content between startPosition/endPosition, and a tree with content following endPosition. 
        // Any of the subtrees may be null on exit, if they contain no content (eg, if
        // startPosition == endPosition, middleSubTree will be null on exit, and so forth).
        //
        // All returned roots have null ParentNode pointers -- the caller MUST 
        // reparent all of them, even if deleting content, to ensure orphaned
        // TextPositions can find their way back to the original tree. 
        // 
        // Returns the symbol count of middleSubTree -- all the content between startPosition and endPosition.
        private int CutContent(TextPointer startPosition, TextPointer endPosition, out int charCount, out SplayTreeNode leftSubTree, out SplayTreeNode middleSubTree, out SplayTreeNode rightSubTree) 
        {
            SplayTreeNode childNode;
            int symbolCount;
 
            Invariant.Assert(startPosition.GetScopingNode() == endPosition.GetScopingNode(), "startPosition/endPosition not in same sibling tree!");
            Invariant.Assert(startPosition.CompareTo(endPosition) != 0, "CutContent doesn't expect empty span!"); 
 
            // Get the root of all nodes to the left of the split.
            switch (startPosition.Edge) 
            {
                case ElementEdge.BeforeStart:
                    leftSubTree = startPosition.Node.GetPreviousNode();
                    break; 

                case ElementEdge.AfterStart: 
                    leftSubTree = null; 
                    break;
 
                case ElementEdge.BeforeEnd:
                default:
                    Invariant.Assert(false, "Unexpected edge!"); // Should have gone to simple insert case.
                    leftSubTree = null; 
                    break;
 
                case ElementEdge.AfterEnd: 
                    leftSubTree = startPosition.Node;
                    break; 
            }

            // Get the root of all nodes to the right of the split.
            switch (endPosition.Edge) 
            {
                case ElementEdge.BeforeStart: 
                    rightSubTree = endPosition.Node; 
                    break;
 
                case ElementEdge.AfterStart:
                default:
                    Invariant.Assert(false, "Unexpected edge! (2)"); // Should have gone to simple insert case.
                    rightSubTree = null; 
                    break;
 
                case ElementEdge.BeforeEnd: 
                    rightSubTree = null;
                    break; 

                case ElementEdge.AfterEnd:
                    rightSubTree = endPosition.Node.GetNextNode();
                    break; 
            }
 
            // Get the root of all nodes covered by startPosition/endPosition. 
            if (rightSubTree == null)
            { 
                if (leftSubTree == null)
                {
                    middleSubTree = startPosition.GetScopingNode().ContainedNode;
                } 
                else
                { 
                    middleSubTree = leftSubTree.GetNextNode(); 
                }
            } 
            else
            {
                middleSubTree = rightSubTree.GetPreviousNode();
                if (middleSubTree == leftSubTree) 
                {
                    middleSubTree = null; 
                } 
            }
 
            // Split the tree into three sub trees matching the roots we've found.

            if (leftSubTree != null)
            { 
                leftSubTree.Split();
                Invariant.Assert(leftSubTree.Role == SplayTreeNodeRole.LocalRoot); 
                leftSubTree.ParentNode.ContainedNode = null; 
                leftSubTree.ParentNode = null;
            } 

            symbolCount = 0;
            charCount = 0;
 
            if (middleSubTree != null)
            { 
                if (rightSubTree != null) 
                {
                    // Split will move middleSubTree up to the root. 
                    middleSubTree.Split();
                }
                else
                { 
                    // Make sure middleSubTree is a root.
                    middleSubTree.Splay(); 
                } 
                Invariant.Assert(middleSubTree.Role == SplayTreeNodeRole.LocalRoot, "middleSubTree is not a local root!");
 
                if (middleSubTree.ParentNode != null)
                {
                    middleSubTree.ParentNode.ContainedNode = null;
                    middleSubTree.ParentNode = null; 
                }
 
                // Calc the symbol count of the middle tree. 
                for (childNode = middleSubTree; childNode != null; childNode = childNode.RightChildNode)
                { 
                    symbolCount += childNode.LeftSymbolCount + childNode.SymbolCount;
                    charCount += childNode.LeftCharCount + childNode.IMECharCount;
                }
            } 

            if (rightSubTree != null) 
            { 
                // Make sure rightSubTree is a root before returning.
                // We haven't done anything yet to ensure this. 
                rightSubTree.Splay();
            }

            Invariant.Assert(leftSubTree == null || leftSubTree.Role == SplayTreeNodeRole.LocalRoot); 
            Invariant.Assert(middleSubTree == null || middleSubTree.Role == SplayTreeNodeRole.LocalRoot);
            Invariant.Assert(rightSubTree == null || rightSubTree.Role == SplayTreeNodeRole.LocalRoot); 
 
            return symbolCount;
        }