Пример #1
0
        /// <summary>
        /// Creates a <see cref="RichTextModel"/> that stores the highlighting of this line.
        /// </summary>
        public RichTextModel ToRichTextModel()
        {
            var builder     = new RichTextModel();
            var startOffset = DocumentLine.Offset;

            foreach (var section in Sections)
            {
                builder.ApplyHighlighting(section.Offset - startOffset, section.Length, section.Color);
            }
            return(builder);
        }
Пример #2
0
 /// <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 };
     }
 }
Пример #3
0
 /// <summary>
 /// Creates a new RichTextColorizer instance.
 /// </summary>
 public RichTextColorizer(RichTextModel richTextModel)
 {
     _richTextModel = richTextModel ?? throw new ArgumentNullException(nameof(richTextModel));
 }