From f72ef6ad798ddc16daa9bb22e111443b9d4125fe Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 1 Jul 2026 21:32:29 +0200 Subject: [PATCH] Guard deferred debug-step highlight scrolling Avoid stale dispatcher callbacks scrolling the editor after a later decompile has cleared or replaced the debug-step highlight. Assisted-by: OpenCode:openai/gpt-5.5:OpenCode --- ILSpy/TextView/DecompilerTextView.axaml.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ILSpy/TextView/DecompilerTextView.axaml.cs b/ILSpy/TextView/DecompilerTextView.axaml.cs index edbb11c0f..4e6fc469b 100644 --- a/ILSpy/TextView/DecompilerTextView.axaml.cs +++ b/ILSpy/TextView/DecompilerTextView.axaml.cs @@ -80,6 +80,7 @@ namespace ICSharpCode.ILSpy.TextView BracketHighlightRenderer bracketHighlightRenderer = null!; readonly List localReferenceMarks = new(); readonly List debugStepMarks = new(); + int debugStepHighlightVersion; readonly List activeCustomGenerators = new(); RichTextColorizer? activeColorizer; FoldingManager? activeFoldingManager; @@ -1278,12 +1279,17 @@ namespace ICSharpCode.ILSpy.TextView // so a newer decompile landing before the post runs can't scroll the wrong content. var document = Editor.Document; var line = document.GetLineByOffset(start).LineNumber; - Dispatcher.UIThread.Post(() => CenterLineInView(document, line), DispatcherPriority.Background); + var highlightVersion = debugStepHighlightVersion; + Dispatcher.UIThread.Post(() => { + if (highlightVersion == debugStepHighlightVersion) + CenterLineInView(document, line); + }, DispatcherPriority.Background); CaretHighlightAdorner.DisplayCaretHighlightAnimation(Editor.TextArea); } void ClearDebugStepMarks() { + debugStepHighlightVersion++; foreach (var mark in debugStepMarks) textMarkerService.Remove(mark); debugStepMarks.Clear();