Skip to content

Commit 2c1b798

Browse files
committed
fix: sometimes line number margin's width does not update
Signed-off-by: leo <longshuang@msn.cn>
1 parent 46d9a20 commit 2c1b798

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/Views/TextDiffView.axaml.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void Render(DrawingContext context)
3535
if (presenter != null)
3636
{
3737
var pen = new Pen(presenter.LineBrush);
38-
context.DrawLine(pen, new Point(0, 0), new Point(0, Bounds.Height));
38+
context.DrawLine(pen, new Point(0.5, 0), new Point(0.5, Bounds.Height));
3939
}
4040
}
4141

@@ -98,23 +98,6 @@ public override void Render(DrawingContext context)
9898
}
9999
}
100100

101-
protected override Size MeasureOverride(Size availableSize)
102-
{
103-
var presenter = this.FindAncestorOfType<ThemedTextDiffPresenter>();
104-
if (presenter is not { DataContext: ViewModels.TextDiffContext ctx })
105-
return new Size(32, 0);
106-
107-
var typeface = TextView.CreateTypeface();
108-
var test = new FormattedText(
109-
$"{ctx.Data.MaxLineNumber}",
110-
CultureInfo.CurrentCulture,
111-
FlowDirection.LeftToRight,
112-
typeface,
113-
presenter.FontSize,
114-
Brushes.White);
115-
return new Size(test.Width, 0);
116-
}
117-
118101
private readonly bool _usePresenter;
119102
private readonly bool _isOld;
120103
}
@@ -588,10 +571,26 @@ protected override void OnDataContextChanged(EventArgs e)
588571
{
589572
base.OnDataContextChanged(e);
590573

591-
foreach (var margin in TextArea.LeftMargins)
574+
if (DataContext is ViewModels.TextDiffContext ctx)
592575
{
593-
if (margin is LineNumberMargin)
594-
margin.InvalidateMeasure();
576+
var typeface = new Typeface(FontFamily);
577+
var test = new FormattedText(
578+
$"{ctx.Data.MaxLineNumber}",
579+
CultureInfo.CurrentCulture,
580+
FlowDirection.LeftToRight,
581+
typeface,
582+
FontSize,
583+
Brushes.White);
584+
585+
var width = test.WidthIncludingTrailingWhitespace;
586+
foreach (var margin in TextArea.LeftMargins)
587+
{
588+
if (margin is LineNumberMargin lineNumberMargin)
589+
margin.Width = width;
590+
}
591+
592+
var dock = TextArea.FindDescendantOfType<DockPanel>();
593+
dock?.InvalidateArrange();
595594
}
596595

597596
AutoScrollToFirstChange();

0 commit comments

Comments
 (0)