コード例 #1
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);
        }
コード例 #2
0
        private 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);
        }
コード例 #3
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }