Exemple #1
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);
 }
 internal void RemoveFromTextView(TextView textView)
 {
     int pos = textViews.IndexOf(textView);
     if (pos < 0)
         throw new ArgumentException();
     textViews.RemoveAt(pos);
     foreach (FoldingSection fs in foldings) {
         if (fs.collapsedSections != null) {
             var c = new CollapsedLineSection[textViews.Count];
             Array.Copy(fs.collapsedSections, 0, c, 0, pos);
             fs.collapsedSections[pos].Uncollapse();
             Array.Copy(fs.collapsedSections, pos + 1, c, pos, c.Length - pos);
             fs.collapsedSections = c;
         }
     }
 }
Exemple #3
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);
     }
 }
Exemple #4
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);
        }
Exemple #5
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }
Exemple #6
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
 }
Exemple #7
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;
 }
 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;
     }
 }
 internal void AddDirectlyCollapsed(CollapsedLineSection section)
 {
     if (collapsedSections == null) {
         collapsedSections = new List<CollapsedLineSection>();
         totalHeight = 0;
     }
     Debug.Assert(!collapsedSections.Contains(section));
     collapsedSections.Add(section);
 }