From 7a3bfb732335722665825425db74bbcfeb76d68f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 27 Jun 2026 07:50:09 +0200 Subject: [PATCH] Center C# debug-step highlights Place the selected debug-step node in the middle of the editor after replay so navigation lands with enough surrounding context instead of just barely scrolling the mark into view. Assisted-by: CodeAlta:gpt-5.5:CodeAlta --- ILSpy/TextView/DecompilerTextView.axaml.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ILSpy/TextView/DecompilerTextView.axaml.cs b/ILSpy/TextView/DecompilerTextView.axaml.cs index 48b0e3d13..4a0e55914 100644 --- a/ILSpy/TextView/DecompilerTextView.axaml.cs +++ b/ILSpy/TextView/DecompilerTextView.axaml.cs @@ -1265,9 +1265,22 @@ namespace ICSharpCode.ILSpy.TextView debugStepMarks.Add(mark); Editor.TextArea.Caret.Offset = start; Editor.TextArea.Caret.BringCaretToView(); + Dispatcher.UIThread.Post(() => CenterDocumentOffsetInView(start)); CaretHighlightAdorner.DisplayCaretHighlightAnimation(Editor.TextArea); } + void CenterDocumentOffsetInView(int offset) + { + if (EditorScrollViewer is not { } scrollViewer || Editor.Document.TextLength == 0) + return; + offset = Math.Clamp(offset, 0, Editor.Document.TextLength); + var line = Editor.Document.GetLineByOffset(offset); + var lineHeight = Editor.TextArea.TextView.DefaultLineHeight; + if (lineHeight <= 0 || scrollViewer.Viewport.Height <= 0) + return; + var targetY = Math.Max(0, (line.LineNumber - 1) * lineHeight - (scrollViewer.Viewport.Height - lineHeight) / 2); + scrollViewer.Offset = new Vector(scrollViewer.Offset.X, targetY); + } void ClearDebugStepMarks() {