fix(diff): install background renderers on attach so themed brushes resolve

This commit is contained in:
mika kuns
2026-08-07 10:25:30 +02:00
parent 51371cf678
commit 2f3f9387c4
@@ -69,17 +69,31 @@ public partial class DiffTextView : UserControl
private ScrollViewer? _leftScroll, _rightScroll;
private bool _scrollHooked;
private bool _syncing;
private bool _renderersInstalled;
public DiffTextView()
{
InitializeComponent();
_leftTm = LeftEditor.InstallTextMate(Registry);
_rightTm = RightEditor.InstallTextMate(Registry);
InstallRenderers();
ReloadFile();
HookScrollSync();
}
/// Brushes and the mono typeface only resolve once the control is in the visual tree —
/// a detached control has no resource parent to walk up to, and its styles haven't been
/// applied yet. Installing the renderers in the constructor would freeze them on their
/// hardcoded fallbacks for good, since they capture their brushes once.
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
if (_renderersInstalled) return;
_renderersInstalled = true;
InstallRenderers();
RebuildMargins();
InvalidateRenderers();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);