diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs index f17de13..0e4f75d 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs @@ -42,6 +42,7 @@ public partial class SharpIdeCodeEdit : CodeEdit private ImmutableArray _projectDiagnosticsForFile = []; private ImmutableArray _currentCodeActionsInPopup = []; private bool _fileChangingSuppressBreakpointToggleEvent; + private bool _settingWholeDocumentTextSuppressLineEditsEvent; // A dodgy workaround - setting the whole document doesn't guarantee that the line count stayed the same etc. We are still going to have broken highlighting. TODO: Investigate getting minimal text change ranges, and change those ranges only [Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!; [Inject] private readonly RunService _runService = null!; @@ -99,6 +100,7 @@ public partial class SharpIdeCodeEdit : CodeEdit private void OnLinesEditedFrom(long fromLine, long toLine) { if (fromLine == toLine) return; + if (_settingWholeDocumentTextSuppressLineEditsEvent) return; var fromLineText = GetLine((int)fromLine); var caretPosition = this.GetCaretPosition(); var textFrom0ToCaret = fromLineText[..caretPosition.col]; @@ -304,17 +306,19 @@ public partial class SharpIdeCodeEdit : CodeEdit private async Task OnFileChangedExternally(SharpIdeFileLinePosition? linePosition) { var fileContents = await _openTabsFileManager.GetFileTextAsync(_currentFile); - Callable.From(() => + await this.InvokeAsync(() => { (int line, int col) currentCaretPosition = linePosition is null ? GetCaretPosition() : (linePosition.Value.Line, linePosition.Value.Column); var vScroll = GetVScroll(); BeginComplexOperation(); + _settingWholeDocumentTextSuppressLineEditsEvent = true; SetText(fileContents); + _settingWholeDocumentTextSuppressLineEditsEvent = false; SetCaretLine(currentCaretPosition.line); SetCaretColumn(currentCaretPosition.col); SetVScroll(vScroll); EndComplexOperation(); - }).CallDeferred(); + }); } public void SetFileLinePosition(SharpIdeFileLinePosition fileLinePosition) diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 87fb314..9a02c19 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Godot; using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.Build; @@ -91,7 +92,10 @@ public partial class IdeRoot : Control // TODO: Problematic, as this is called even when the focus shifts to an embedded subwindow, such as a popup private void OnFocusExited() { - _ = Task.GodotRun(async () => await _openTabsFileManager.SaveAllOpenFilesAsync()); + if (Debugger.IsAttached is false) + { + _ = Task.GodotRun(async () => await _openTabsFileManager.SaveAllOpenFilesAsync()); + } } private void OnRunMenuButtonPressed()