/// <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); } }
/// <inheritdoc/> public override int GetFirstInterestedOffset(int startOffset) { if (_foldingManager != null) { foreach (var fs in _foldingManager.GetFoldingsContaining(startOffset)) { // Test whether we're currently within a folded folding (that didn't just end). // If so, create the fold marker immediately. // This is necessary if the actual beginning of the fold marker got skipped due to another VisualElementGenerator. if (fs.IsFolded && fs.EndOffset > startOffset) { //return startOffset; } } return(_foldingManager.GetNextFoldedFoldingStart(startOffset)); } else { return(-1); } }