|
4 | 4 | using Avalonia.Controls; |
5 | 5 | using Avalonia.Controls.Primitives; |
6 | 6 | using Avalonia.Interactivity; |
| 7 | +using Avalonia.Media; |
7 | 8 |
|
8 | 9 | using AvaloniaEdit; |
9 | 10 | using AvaloniaEdit.Document; |
10 | 11 | using AvaloniaEdit.Editing; |
| 12 | +using AvaloniaEdit.Rendering; |
11 | 13 | using AvaloniaEdit.TextMate; |
12 | 14 |
|
13 | 15 | namespace SourceGit.Views |
14 | 16 | { |
15 | 17 | public class LogContentPresenter : TextEditor |
16 | 18 | { |
| 19 | + public class LineStyleTransformer : DocumentColorizingTransformer |
| 20 | + { |
| 21 | + protected override void ColorizeLine(DocumentLine line) |
| 22 | + { |
| 23 | + var content = CurrentContext.Document.GetText(line); |
| 24 | + if (content.StartsWith("$ git ", StringComparison.Ordinal)) |
| 25 | + { |
| 26 | + ChangeLinePart(line.Offset, line.Offset + 1, v => |
| 27 | + { |
| 28 | + v.TextRunProperties.SetForegroundBrush(Brushes.Orange); |
| 29 | + }); |
| 30 | + |
| 31 | + ChangeLinePart(line.Offset + 2, line.EndOffset, v => |
| 32 | + { |
| 33 | + var old = v.TextRunProperties.Typeface; |
| 34 | + v.TextRunProperties.SetTypeface(new Typeface(old.FontFamily, old.Style, FontWeight.Bold)); |
| 35 | + }); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
17 | 40 | public static readonly StyledProperty<ViewModels.CommandLog> LogProperty = |
18 | 41 | AvaloniaProperty.Register<LogContentPresenter, ViewModels.CommandLog>(nameof(Log)); |
19 | 42 |
|
@@ -46,6 +69,7 @@ protected override void OnLoaded(RoutedEventArgs e) |
46 | 69 | { |
47 | 70 | _textMate = Models.TextMateHelper.CreateForEditor(this); |
48 | 71 | Models.TextMateHelper.SetGrammarByFileName(_textMate, "Log.log"); |
| 72 | + TextArea.TextView.LineTransformers.Add(new LineStyleTransformer()); |
49 | 73 | } |
50 | 74 | } |
51 | 75 |
|
|
0 commit comments