Ejemplo n.º 1
0
        void AddRemoveCollapsedSection(CollapsedLineSection section, int sectionLength, bool add)
        {
            Debug.Assert(sectionLength > 0);

            HeightTreeNode node = GetNode(section.Start);

            // Go up in the tree.
            while (true)
            {
                // Mark all middle nodes as collapsed
                if (add)
                {
                    node.lineNode.AddDirectlyCollapsed(section);
                }
                else
                {
                    node.lineNode.RemoveDirectlyCollapsed(section);
                }
                sectionLength -= 1;
                if (sectionLength == 0)
                {
                    // we are done!
                    Debug.Assert(node.documentLine == section.End);
                    break;
                }
                // Mark all right subtrees as collapsed.
                if (node.right != null)
                {
                    if (node.right.totalCount < sectionLength)
                    {
                        if (add)
                        {
                            node.right.AddDirectlyCollapsed(section);
                        }
                        else
                        {
                            node.right.RemoveDirectlyCollapsed(section);
                        }
                        sectionLength -= node.right.totalCount;
                    }
                    else
                    {
                        // mark partially into the right subtree: go down the right subtree.
                        AddRemoveCollapsedSectionDown(section, node.right, sectionLength, add);
                        break;
                    }
                }
                // go up to the next node
                HeightTreeNode parentNode = node.parent;
                Debug.Assert(parentNode != null);
                while (parentNode.right == node)
                {
                    node       = parentNode;
                    parentNode = node.parent;
                    Debug.Assert(parentNode != null);
                }
                node = parentNode;
            }
            UpdateAugmentedData(GetNode(section.Start), UpdateAfterChildrenChangeRecursionMode.WholeBranch);
            UpdateAugmentedData(GetNode(section.End), UpdateAfterChildrenChangeRecursionMode.WholeBranch);
        }
Ejemplo n.º 2
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }