Example #1
0
 internal void RemoveDirectlyCollapsed(CollapsedLineSection section)
 {
     Debug.Assert(collapsedSections.Contains(section));
     collapsedSections.Remove(section);
     if (collapsedSections.Count == 0)
         collapsedSections = null;
 }
Example #2
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);
        }
Example #3
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }
Example #4
0
 internal void RemoveDirectlyCollapsed(CollapsedLineSection section)
 {
     Debug.Assert(collapsedSections.Contains(section));
     collapsedSections.Remove(section);
     if (collapsedSections.Count == 0) {
         collapsedSections = null;
         totalHeight = lineNode.TotalHeight;
         if (left != null)
             totalHeight += left.totalHeight;
         if (right != null)
             totalHeight += right.totalHeight;
     }
 }
Example #5
0
 internal void AddDirectlyCollapsed(CollapsedLineSection section)
 {
     if (collapsedSections == null) {
         collapsedSections = new List<CollapsedLineSection>();
         totalHeight = 0;
     }
     Debug.Assert(!collapsedSections.Contains(section));
     collapsedSections.Add(section);
 }
Example #6
0
 void CheckIsInSection(CollapsedLineSection cs, DocumentLine line)
 {
     HeightTreeNode node = GetNode(line);
     if (node.lineNode.collapsedSections != null && node.lineNode.collapsedSections.Contains(cs))
         return;
     while (node != null) {
         if (node.collapsedSections != null && node.collapsedSections.Contains(cs))
             return;
         node = node.parent;
     }
     throw new InvalidOperationException(cs + " not found for line " + line);
 }
Example #7
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);
        }
Example #8
0
 static void AddRemoveCollapsedSectionDown(CollapsedLineSection section, HeightTreeNode node, int sectionLength, bool add)
 {
     while (true) {
         if (node.left != null) {
             if (node.left.totalCount < sectionLength) {
                 // mark left subtree
                 if (add)
                     node.left.AddDirectlyCollapsed(section);
                 else
                     node.left.RemoveDirectlyCollapsed(section);
                 sectionLength -= node.left.totalCount;
             } else {
                 // mark only inside the left subtree
                 node = node.left;
                 Debug.Assert(node != null);
                 continue;
             }
         }
         if (add)
             node.lineNode.AddDirectlyCollapsed(section);
         else
             node.lineNode.RemoveDirectlyCollapsed(section);
         sectionLength -= 1;
         if (sectionLength == 0) {
             // done!
             Debug.Assert(node.documentLine == section.End);
             break;
         }
         // mark inside right subtree:
         node = node.right;
         Debug.Assert(node != null);
     }
 }
Example #9
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }
Example #10
0
 public void Uncollapse(CollapsedLineSection section)
 {
     int sectionLength = section.End.LineNumber - section.Start.LineNumber + 1;
     AddRemoveCollapsedSection(section, sectionLength, false);
     // do not call CheckProperties() in here - Uncollapse is also called during line removals
 }
Example #11
0
 /// <summary>
 /// Collapses the specified text section.
 /// Runtime: O(log n)
 /// </summary>
 public CollapsedLineSection CollapseText(DocumentLine start, DocumentLine end)
 {
     if (!document.Lines.Contains(start))
         throw new ArgumentException("Line is not part of this document", "start");
     if (!document.Lines.Contains(end))
         throw new ArgumentException("Line is not part of this document", "end");
     int length = end.LineNumber - start.LineNumber + 1;
     if (length < 0)
         throw new ArgumentException("start must be a line before end");
     CollapsedLineSection section = new CollapsedLineSection(this, start, end);
     AddCollapsedSection(section, length);
     #if DEBUG
     CheckProperties();
     #endif
     return section;
 }
Example #12
0
 internal void AddDirectlyCollapsed(CollapsedLineSection section)
 {
     if (collapsedSections == null)
         collapsedSections = new List<CollapsedLineSection>();
     collapsedSections.Add(section);
 }