/// <inheritdoc/> protected override void ColorizeLine(DocumentLine line) { var sections = _richTextModel.GetHighlightedSections(line.Offset, line.Length); foreach (var section in sections) { if (HighlightingColorizer.IsEmptyColor(section.Color)) { continue; } ChangeLinePart(section.Offset, section.Offset + section.Length, visualLineElement => HighlightingColorizer.ApplyColorToElement(visualLineElement, section.Color, CurrentContext)); } }
/// <summary> /// Creates a RichText instance with the given text and RichTextModel. /// </summary> /// <param name="text"> /// The text to use in this RichText instance. /// </param> /// <param name="model"> /// The model that contains the formatting to use for this RichText instance. /// <c>model.DocumentLength</c> should correspond to <c>text.Length</c>. /// This parameter may be null, in which case the RichText instance just holds plain text. /// </param> public RichText(string text, RichTextModel model = null) { Text = text ?? throw new ArgumentNullException(nameof(text)); if (model != null) { var sections = model.GetHighlightedSections(0, text.Length).ToArray(); StateChangeOffsets = new int[sections.Length]; StateChanges = new HighlightingColor[sections.Length]; for (var i = 0; i < sections.Length; i++) { StateChangeOffsets[i] = sections[i].Offset; StateChanges[i] = sections[i].Color; } } else { StateChangeOffsets = new[] { 0 }; StateChanges = new[] { HighlightingColor.Empty }; } }