internal void Redraw(FoldingSection fs) { foreach (var textView in TextViews) { textView.Redraw(fs); } }
/// <summary> /// Removes a folding section from this manager. /// </summary> public void RemoveFolding(FoldingSection fs) { if (fs == null) { throw new ArgumentNullException(nameof(fs)); } fs.IsFolded = false; _foldings.Remove(fs); Redraw(fs); }
/// <inheritdoc/> public override VisualLineElement ConstructElement(int offset) { if (_foldingManager == null) { return(null); } var foldedUntil = -1; FoldingSection foldingSection = null; foreach (var fs in _foldingManager.GetFoldingsContaining(offset)) { if (fs.IsFolded) { if (fs.EndOffset > foldedUntil) { foldedUntil = fs.EndOffset; foldingSection = fs; } } } if (foldedUntil > offset && foldingSection != null) { // Handle overlapping foldings: if there's another folded folding // (starting within the foldingSection) that continues after the end of the folded section, // then we'll extend our fold element to cover that overlapping folding. bool foundOverlappingFolding; do { foundOverlappingFolding = false; foreach (var fs in FoldingManager.GetFoldingsContaining(foldedUntil)) { if (fs.IsFolded && fs.EndOffset > foldedUntil) { foldedUntil = fs.EndOffset; foundOverlappingFolding = true; } } } while (foundOverlappingFolding); var title = foldingSection.Title; if (string.IsNullOrEmpty(title)) { title = "..."; } var p = CurrentContext.GlobalTextRunProperties.Clone(); p.ForegroundBrush = TextBrush; var textFormatter = TextFormatterFactory.Create(); var text = FormattedTextElement.PrepareText(textFormatter, title, p); return(new FoldingLineElement(foldingSection, text, foldedUntil - offset, TextBrush)); } else { return(null); } }
/// <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"); } if (startOffset < 0 || endOffset > Document.TextLength) { throw new ArgumentException("Folding must be within document boundary"); } var fs = new FoldingSection(this, startOffset, endOffset); _foldings.Add(fs); Redraw(fs); return(fs); }
public FoldingLineElement(FoldingSection fs, TextLine text, int documentLength, IBrush textBrush) : base(text, documentLength) { _fs = fs; _textBrush = textBrush; }