fix: left margins of text editor do not update after FontSize changed (#2276)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-04-17 20:02:07 +08:00
parent 770a9184ba
commit 8713e5866d
2 changed files with 23 additions and 25 deletions

View File

@@ -351,8 +351,6 @@ namespace SourceGit.Views
Models.TextMateHelper.SetThemeByApp(_textMate);
else if (change.Property == SelectedChunkProperty)
TextArea.TextView.InvalidateVisual();
else if (change.Property == MaxLineNumberProperty)
TextArea.LeftMargins[0].InvalidateMeasure();
}
private void UpdateContent()
@@ -439,6 +437,9 @@ namespace SourceGit.Views
return;
}
foreach (var margin in TextArea.LeftMargins)
margin.InvalidateMeasure();
var lines = Lines;
var start = int.MaxValue;
var count = 0;

View File

@@ -98,6 +98,23 @@ namespace SourceGit.Views
}
}
protected override Size MeasureOverride(Size availableSize)
{
if (DataContext is not ViewModels.TextDiffContext ctx)
return new Size(0, 0);
var typeface = new Typeface(TextArea.FontFamily);
var test = new FormattedText(
$"{ctx.Data.MaxLineNumber}",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
TextArea.FontSize,
Brushes.White);
return new Size(test.Width, 0);
}
private readonly bool _usePresenter;
private readonly bool _isOld;
}
@@ -578,29 +595,6 @@ namespace SourceGit.Views
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is ViewModels.TextDiffContext ctx)
{
var typeface = new Typeface(FontFamily);
var test = new FormattedText(
$"{ctx.Data.MaxLineNumber}",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
FontSize,
Brushes.White);
var width = test.WidthIncludingTrailingWhitespace;
foreach (var margin in TextArea.LeftMargins)
{
if (margin is LineNumberMargin lineNumberMargin)
margin.Width = width;
}
var dock = TextArea.FindDescendantOfType<DockPanel>();
dock?.InvalidateArrange();
}
AutoScrollToFirstChange();
}
@@ -721,6 +715,9 @@ namespace SourceGit.Views
if (DataContext is not ViewModels.TextDiffContext ctx)
return;
foreach (var margin in TextArea.LeftMargins)
margin.InvalidateMeasure();
if (ctx.IsSideBySide() && !IsOld)
return;