/// <summary> /// Gets the first offset greater or equal to <paramref name="startOffset"/> where a folded folding starts. /// Returns -1 if there are no foldings after <paramref name="startOffset"/>. /// </summary> public int GetNextFoldedFoldingStart(int startOffset) { FoldingSection fs = foldings.FindFirstSegmentWithStartAfter(startOffset); while (fs != null && !fs.IsFolded) { fs = foldings.GetNextSegment(fs); } return(fs != null ? fs.StartOffset : -1); }
/// <summary> /// Gets all foldings that start exactly at <paramref name="startOffset"/>. /// </summary> public ReadOnlyCollection <FoldingSection> GetFoldingsAt(int startOffset) { List <FoldingSection> result = new List <FoldingSection>(); FoldingSection fs = foldings.FindFirstSegmentWithStartAfter(startOffset); while (fs != null && fs.StartOffset == startOffset) { result.Add(fs); fs = foldings.GetNextSegment(fs); } return(result.AsReadOnly()); }
/// <summary> /// Creates a folding for the specified text section. /// </summary> public FoldingSection CreateFolding(int startOffset, int endOffset) { if (startOffset >= endOffset) { throw new ArgumentException("startOffset must be less than endOffset"); } FoldingSection fs = new FoldingSection(this, startOffset, endOffset); foldings.Add(fs); textView.Redraw(); return(fs); }
void TextViewVisualLinesChanged(object sender, EventArgs e) { foreach (FoldingMarginMarker m in markers) { RemoveVisualChild(m); } markers.Clear(); InvalidateVisual(); if (TextView != null && FoldingManager != null && TextView.VisualLinesValid) { foreach (VisualLine line in TextView.VisualLines) { FoldingSection fs = FoldingManager.GetNextFolding(line.FirstDocumentLine.Offset); if (fs == null) { continue; } if (fs.StartOffset <= line.LastDocumentLine.Offset + line.LastDocumentLine.Length) { FoldingMarginMarker m = new FoldingMarginMarker { IsExpanded = !fs.IsFolded, SnapsToDevicePixels = true, VisualLine = line, FoldingSection = fs }; markers.Add(m); AddVisualChild(m); m.IsMouseDirectlyOverChanged += delegate { InvalidateVisual(); }; InvalidateMeasure(); continue; } } } }
internal void RemoveFolding(FoldingSection fs) { document.VerifyAccess(); foldings.Remove(fs); textView.Redraw(); }