Ejemplo n.º 1
0
 internal void RemoveDirectlyCollapsed(CollapsedLineSection section)
 {
     Debug.Assert(collapsedSections.Contains(section));
     collapsedSections.Remove(section);
     if (collapsedSections.Count == 0)
         collapsedSections = null;
 }
Ejemplo n.º 2
0
		void RemoveCollapsedLineSection()
		{
			if (collapsedSection != null) {
				if (collapsedSection.Start != null)
					collapsedSection.Uncollapse();
				collapsedSection = null;
			}
		}
		internal void Removed()
		{
			if (collapsedSection != null) {
				collapsedSection.Uncollapse();
				collapsedSection = null;
			}
			manager = null;
		}
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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
		}
Ejemplo n.º 6
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);
			}
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 8
0
		internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
		{
			AddRemoveCollapsedSection(section, sectionLength, true);
		}
Ejemplo n.º 9
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.º 10
0
 internal void AddCollapsedSection(CollapsedLineSection section, int sectionLength)
 {
     AddRemoveCollapsedSection(section, sectionLength, true);
 }
Ejemplo n.º 11
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;
			}
		}
Ejemplo n.º 12
0
		internal void AddDirectlyCollapsed(CollapsedLineSection section)
		{
			if (collapsedSections == null) {
				collapsedSections = new List<CollapsedLineSection>();
				totalHeight = 0;
			}
			Debug.Assert(!collapsedSections.Contains(section));
			collapsedSections.Add(section);
		}
Ejemplo n.º 13
0
 internal void AddDirectlyCollapsed(CollapsedLineSection section)
 {
     if (collapsedSections == null)
         collapsedSections = new List<CollapsedLineSection>();
     collapsedSections.Add(section);
 }
Ejemplo n.º 14
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;
		}
Ejemplo n.º 15
0
 internal void RemoveFromTextView(TextView textView)
 {
     int pos = textViews.IndexOf(textView);
     if (pos < 0)
         throw new ArgumentException();
     foreach (FoldingSection fs in foldings)
     {
         if (fs.collapsedSections != null)
         {
             var c = new CollapsedLineSection[textViews.Count];
             Array.Copy(fs.collapsedSections, 0, c, 0, pos);
             Array.Copy(fs.collapsedSections, pos + 1, c, pos, c.Length - pos);
             fs.collapsedSections = c;
         }
     }
 }
Ejemplo n.º 16
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);
		}
Ejemplo n.º 17
0
		internal CollapsedLineSection[] CollapseLines(DocumentLine start, DocumentLine end)
		{
			CollapsedLineSection[] c = new CollapsedLineSection[textViews.Count];
			for (int i = 0; i < c.Length; i++) {
				c[i] = textViews[i].CollapseLines(start, end);
			}
			return c;
		}