Skip to content

Commit 8713e58

Browse files
committed
fix: left margins of text editor do not update after FontSize changed (sourcegit-scm#2276)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 770a918 commit 8713e58

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/Views/MergeConflictEditor.axaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
351351
Models.TextMateHelper.SetThemeByApp(_textMate);
352352
else if (change.Property == SelectedChunkProperty)
353353
TextArea.TextView.InvalidateVisual();
354-
else if (change.Property == MaxLineNumberProperty)
355-
TextArea.LeftMargins[0].InvalidateMeasure();
356354
}
357355

358356
private void UpdateContent()
@@ -439,6 +437,9 @@ private void OnTextViewVisualLinesChanged(object sender, EventArgs e)
439437
return;
440438
}
441439

440+
foreach (var margin in TextArea.LeftMargins)
441+
margin.InvalidateMeasure();
442+
442443
var lines = Lines;
443444
var start = int.MaxValue;
444445
var count = 0;

src/Views/TextDiffView.axaml.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ public override void Render(DrawingContext context)
9898
}
9999
}
100100

101+
protected override Size MeasureOverride(Size availableSize)
102+
{
103+
if (DataContext is not ViewModels.TextDiffContext ctx)
104+
return new Size(0, 0);
105+
106+
var typeface = new Typeface(TextArea.FontFamily);
107+
var test = new FormattedText(
108+
$"{ctx.Data.MaxLineNumber}",
109+
CultureInfo.CurrentCulture,
110+
FlowDirection.LeftToRight,
111+
typeface,
112+
TextArea.FontSize,
113+
Brushes.White);
114+
115+
return new Size(test.Width, 0);
116+
}
117+
101118
private readonly bool _usePresenter;
102119
private readonly bool _isOld;
103120
}
@@ -578,29 +595,6 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
578595
protected override void OnDataContextChanged(EventArgs e)
579596
{
580597
base.OnDataContextChanged(e);
581-
582-
if (DataContext is ViewModels.TextDiffContext ctx)
583-
{
584-
var typeface = new Typeface(FontFamily);
585-
var test = new FormattedText(
586-
$"{ctx.Data.MaxLineNumber}",
587-
CultureInfo.CurrentCulture,
588-
FlowDirection.LeftToRight,
589-
typeface,
590-
FontSize,
591-
Brushes.White);
592-
593-
var width = test.WidthIncludingTrailingWhitespace;
594-
foreach (var margin in TextArea.LeftMargins)
595-
{
596-
if (margin is LineNumberMargin lineNumberMargin)
597-
margin.Width = width;
598-
}
599-
600-
var dock = TextArea.FindDescendantOfType<DockPanel>();
601-
dock?.InvalidateArrange();
602-
}
603-
604598
AutoScrollToFirstChange();
605599
}
606600

@@ -721,6 +715,9 @@ private void OnTextViewVisualLinesChanged(object sender, EventArgs e)
721715
if (DataContext is not ViewModels.TextDiffContext ctx)
722716
return;
723717

718+
foreach (var margin in TextArea.LeftMargins)
719+
margin.InvalidateMeasure();
720+
724721
if (ctx.IsSideBySide() && !IsOld)
725722
return;
726723

0 commit comments

Comments
 (0)