From dbd43a4b1bb4613fc58064ad32c4b75c9258bed2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 9 Jun 2026 13:37:32 +0200 Subject: [PATCH] Extract the colorizer swap into SetColorizer ApplyDocument and the theme-change rebuild both removed the active RichTextColorizer, nulled the reference, and added a new one. Pull that into SetColorizer(RichTextModel?) -- a null model just clears it -- so the two callers only supply the model (the per-document one, or the one rebuilt from the captured spans on a palette change). Assisted-by: Claude:claude-opus-4-8:Claude Code --- ILSpy/TextView/DecompilerTextView.axaml.cs | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ILSpy/TextView/DecompilerTextView.axaml.cs b/ILSpy/TextView/DecompilerTextView.axaml.cs index cbcdaf4fa..c08d3c858 100644 --- a/ILSpy/TextView/DecompilerTextView.axaml.cs +++ b/ILSpy/TextView/DecompilerTextView.axaml.cs @@ -247,18 +247,29 @@ namespace ILSpy.TextView { if (boundModel?.HighlightingSpans is not { Count: > 0 } spans) return; + var model = new RichTextModel(); + foreach (var (start, length, color) in spans) + model.SetHighlighting(start, length, color); + SetColorizer(model); + Editor.TextArea.TextView.Redraw(); + } + + // Swap the semantic-highlighting colorizer to one for , or remove it + // when null. AvaloniaEdit only exposes Add/Remove on LineTransformers, so we hold a reference + // to the live one. Shared by ApplyDocument (per-document model) and the theme-change rebuild. + void SetColorizer(RichTextModel? model) + { var transformers = Editor.TextArea.TextView.LineTransformers; if (activeColorizer != null) { transformers.Remove(activeColorizer); activeColorizer = null; } - var model = new RichTextModel(); - foreach (var (start, length, color) in spans) - model.SetHighlighting(start, length, color); - activeColorizer = new RichTextColorizer(model); - transformers.Add(activeColorizer); - Editor.TextArea.TextView.Redraw(); + if (model != null) + { + activeColorizer = new RichTextColorizer(model); + transformers.Add(activeColorizer); + } } void OnEditorPointerWheelChanged(object? sender, PointerWheelEventArgs e) @@ -590,19 +601,8 @@ namespace ILSpy.TextView Editor.SyntaxHighlighting = HighlightingService.GetByExtension(model.SyntaxExtension); Editor.Document.Text = model.Text; - // Swap the semantic-highlighting colorizer. AvaloniaEdit only exposes Add/Remove on - // LineTransformers, so we keep a reference to the previous one. - var transformers = Editor.TextArea.TextView.LineTransformers; - if (activeColorizer != null) - { - transformers.Remove(activeColorizer); - activeColorizer = null; - } - if (model.HighlightingModel is { } richModel) - { - activeColorizer = new RichTextColorizer(richModel); - transformers.Add(activeColorizer); - } + // Swap the semantic-highlighting colorizer for this document's model (null clears it). + SetColorizer(model.HighlightingModel); // Folding markers in the gutter: install lazily so editors with no foldings stay // chrome-free. UpdateFoldings expects offsets sorted ascending.