From f6e1e65a5341fa32523b1737a2115375bbbcec6d Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 23 Oct 2024 12:03:22 +0800 Subject: [PATCH] feature: add `+`/`-` in line number to indicate type of change (#593) --- src/Views/TextDiffView.axaml.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index dd3471bf..4a450e0a 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -105,6 +105,32 @@ namespace SourceGit.Views continue; var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.LineMiddle) - view.VerticalOffset; + + var prefix = null as FormattedText; + if (info.Type == Models.TextDiffLineType.Added) + { + prefix = new FormattedText( + "+", + CultureInfo.CurrentCulture, + FlowDirection.LeftToRight, + typeface, + presenter.FontSize, + Brushes.Green); + } + else if (info.Type == Models.TextDiffLineType.Deleted) + { + prefix = new FormattedText( + "-", + CultureInfo.CurrentCulture, + FlowDirection.LeftToRight, + typeface, + presenter.FontSize, + Brushes.Red); + } + + if (prefix != null) + context.DrawText(prefix, new Point(0, y - prefix.Height * 0.5)); + var txt = new FormattedText( lineNumber, CultureInfo.CurrentCulture, @@ -126,7 +152,7 @@ namespace SourceGit.Views var maxLineNumber = presenter.GetMaxLineNumber(); var typeface = TextView.CreateTypeface(); var test = new FormattedText( - $"{maxLineNumber}", + $"- {maxLineNumber}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface,