diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.SelectionChanged.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.SelectionChanged.cs new file mode 100644 index 0000000..0e2a425 --- /dev/null +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.SelectionChanged.cs @@ -0,0 +1,31 @@ +using Microsoft.CodeAnalysis.Threading; + +namespace SharpIDE.Godot.Features.CodeEditor; + +public partial class SharpIdeCodeEdit +{ + private readonly AsyncBatchingWorkQueue _selectionChangedQueue; + + private async ValueTask ProcessSelectionChanged(CancellationToken cancellationToken) + { + if (cancellationToken.IsCancellationRequested) return; + string? selectedText = null; + await this.InvokeAsync(() => + { + if (HasSelection() is false) return; + selectedText = GetSelectedText(); + }); + if (string.IsNullOrWhiteSpace(selectedText)) return; + var lineBreakCount = 0; + var slashRsToRemove = 0; + + foreach (var c in selectedText.AsSpan()) + { + if (c is '\n') lineBreakCount++; + else if (c is '\r') slashRsToRemove++; + } + + var charLength = selectedText.Length - lineBreakCount - slashRsToRemove; + _editorCaretPositionService.SelectionInfo = (charLength, lineBreakCount); + } +} \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs index 6d03c8f..ecb06c2 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs @@ -13,7 +13,6 @@ using Roslyn.Utilities; using SharpIDE.Application; using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.Analysis.Razor; -using SharpIDE.Application.Features.Debugging; using SharpIDE.Application.Features.Editor; using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.FilePersistence; @@ -48,7 +47,6 @@ public partial class SharpIdeCodeEdit : CodeEdit 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 private bool _fileDeleted; private IDisposable? _projectDiagnosticsObserveDisposable; - private readonly AsyncBatchingWorkQueue _selectionChangedQueue; [Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!; [Inject] private readonly RunService _runService = null!; @@ -214,28 +212,6 @@ public partial class SharpIdeCodeEdit : CodeEdit SetSymbolLookupWordAsValid(true); } - private async ValueTask ProcessSelectionChanged(CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) return; - string? selectedText = null; - await this.InvokeAsync(() => - { - if (HasSelection() is false) return; - selectedText = GetSelectedText(); - }); - if (string.IsNullOrWhiteSpace(selectedText)) return; - var lineBreakCount = 0; - var slashRsToRemove = 0; - - foreach (var c in selectedText.AsSpan()) - { - if (c is '\n') lineBreakCount++; - else if (c is '\r') slashRsToRemove++; - } - var charLength = selectedText.Length - lineBreakCount - slashRsToRemove; - _editorCaretPositionService.SelectionInfo = (charLength, lineBreakCount); - } - private void OnCaretChanged() { var caretPosition = GetCaretPosition(startAt1: true);