1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.AvalonEdit.Document;
7
using ICSharpCode.AvalonEdit.Rendering;
9
namespace ICSharpCode.AvalonEdit.Editing
11
sealed class SelectionColorizer : ColorizingTransformer
15
public SelectionColorizer(TextArea textArea)
18
throw new ArgumentNullException("textArea");
19
this.textArea = textArea;
22
protected override void Colorize(ITextRunConstructionContext context)
24
// if SelectionForeground is null, keep the existing foreground color
25
if (textArea.SelectionForeground == null)
28
int lineStartOffset = context.VisualLine.FirstDocumentLine.Offset;
29
int lineEndOffset = context.VisualLine.LastDocumentLine.Offset + context.VisualLine.LastDocumentLine.TotalLength;
31
foreach (ISegment segment in textArea.Selection.Segments) {
32
int segmentStart = segment.Offset;
33
int segmentEnd = segment.Offset + segment.Length;
34
if (segmentEnd <= lineStartOffset)
36
if (segmentStart >= lineEndOffset)
38
int startColumn = context.VisualLine.GetVisualColumn(Math.Max(0, segmentStart - lineStartOffset));
39
int endColumn = context.VisualLine.GetVisualColumn(segmentEnd - lineStartOffset);
41
startColumn, endColumn,
43
element.TextRunProperties.SetForegroundBrush(textArea.SelectionForeground);