From ccee457dff2a61ca5081b40fcc6aab472f7d74e8 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 21 Jan 2026 01:50:37 +1000 Subject: [PATCH] debugger - move caret and scroll to stopped events --- .../Features/CodeEditor/CodeEditorPanel.cs | 17 +++++++++-------- .../Features/CodeEditor/SharpIdeCodeEdit.cs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs index b38b730..f2f0ec8 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs @@ -169,15 +169,16 @@ public partial class CodeEditorPanel : MarginContainer { Guard.Against.Null(Solution, nameof(Solution)); - var currentSharpIdeFile = await this.InvokeAsync(() => _tabContainer.GetChild(_tabContainer.CurrentTab).SharpIdeFile); - - if (executionStopInfo.FilePath != currentSharpIdeFile?.Path) - { - var file = Solution.AllFiles[executionStopInfo.FilePath]; - await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, null).ConfigureAwait(false); - } var lineInt = executionStopInfo.Line - 1; // Debugging is 1-indexed, Godot is 0-indexed - Guard.Against.Negative(lineInt, nameof(lineInt)); + Guard.Against.Negative(lineInt); + + var file = Solution.AllFiles[executionStopInfo.FilePath]; + // A line being darkened by the caret being on that line completely obscures the executing line color, so as a "temporary" workaround, move the caret to the previous line + // Ideally, like Rider, we would only yellow highlight the sequence point range, with the cursor line black being behind it + var fileLinePosition = new SharpIdeFileLinePosition(lineInt is 0 ? 0 : lineInt - 1, 0); + // Although the file may already be the selected tab, we need to also move the caret + await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, fileLinePosition).ConfigureAwait(false); + if (_debuggerExecutionStopInfoByProject.TryGetValue(executionStopInfo.Project, out _)) throw new InvalidOperationException("Debugger is already stopped for this project."); _debuggerExecutionStopInfoByProject[executionStopInfo.Project] = executionStopInfo; diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs index ecb06c2..d7ad9ea 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs @@ -278,7 +278,7 @@ public partial class SharpIdeCodeEdit : CodeEdit Callable.From(() => { GrabFocus(); - CenterViewportToCaret(); + AdjustViewportToCaret(); }).CallDeferred(); }