From cad64f6352e21e63d87970a7c8b0921df89061b0 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 20 Nov 2020 15:46:06 +0800 Subject: [PATCH] optimize: using ItemsControl instead of TextBox to show line numbers --- src/UI/Blame.xaml | 49 ++++++++++++++++++++++++++++++-------------- src/UI/Blame.xaml.cs | 24 +++++++++++++--------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/UI/Blame.xaml b/src/UI/Blame.xaml index c2186c63..f356c551 100644 --- a/src/UI/Blame.xaml +++ b/src/UI/Blame.xaml @@ -110,30 +110,49 @@ + + - + + + + + + - + + + + + + + + + + + + + + + + numbers = new List(); + for (int i = 0; i < blame.LineCount; i++) numbers.Add(i.ToString()); + lineNumber.ItemsSource = numbers; + + var fg = FindResource("Brush.FG") as SolidColorBrush; + var tf = new Typeface(content.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); + var ns = new NumberSubstitution(); + var mp = new Thickness(0); for (int i = 0; i < blame.Blocks.Count; i++) { var frag = blame.Blocks[i]; @@ -78,11 +82,11 @@ namespace SourceGit.UI { Paragraph p = new Paragraph(new Run(frag.Content)); p.DataContext = frag; - p.Margin = new Thickness(0); - p.Padding = new Thickness(0); + p.Margin = mp; + p.Padding = mp; p.LineHeight = 1; p.Background = BG[i % 2]; - p.Foreground = FindResource("Brush.FG") as SolidColorBrush; + p.Foreground = fg; p.FontStyle = FontStyles.Normal; p.ContextMenuOpening += (sender, ev) => { if (!content.Selection.IsEmpty) return; @@ -114,10 +118,10 @@ namespace SourceGit.UI { frag.Content, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, - new Typeface(content.FontFamily, p.FontStyle, p.FontWeight, p.FontStretch), + tf, content.FontSize, Brushes.Black, - new NumberSubstitution(), + ns, TextFormattingMode.Ideal); if (minWidth < formatter.Width) { content.Document.PageWidth = formatter.Width + 16;