current caret position on tab change
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SharpIDE.Application.Features.Analysis;
|
||||
using SharpIDE.Application.Features.Build;
|
||||
using SharpIDE.Application.Features.Editor;
|
||||
using SharpIDE.Application.Features.Evaluation;
|
||||
using SharpIDE.Application.Features.FilePersistence;
|
||||
using SharpIDE.Application.Features.FileWatching;
|
||||
@@ -35,6 +36,7 @@ public static class DependencyInjection
|
||||
services.AddScoped<IdeFileOperationsService>();
|
||||
services.AddScoped<SharpIdeSolutionModificationService>();
|
||||
services.AddScoped<AnalyzerFileWatcher>();
|
||||
services.AddScoped<EditorCaretPositionService>();
|
||||
services.AddLogging();
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SharpIDE.Application.Features.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// Used by code editor windows to report the current caret position for display elsewhere in the UI
|
||||
/// </summary>
|
||||
public class EditorCaretPositionService
|
||||
{
|
||||
public (int, int) CaretPosition { get; set; } = (1, 1);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Godot;
|
||||
using SharpIDE.Application.Features.Editor;
|
||||
|
||||
namespace SharpIDE.Godot.Features.BottomBar;
|
||||
|
||||
public partial class EditorLineCharDisplay : HBoxContainer
|
||||
{
|
||||
private Label _label = null!;
|
||||
[Inject] private readonly EditorCaretPositionService _editorCaretPositionService = null!;
|
||||
|
||||
private (int, int) _currentPositionRendered = (1, 1);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_label = GetNode<Label>("Label");
|
||||
}
|
||||
|
||||
// Not sure if we should check this every frame, or an event with debouncing?
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var caretPosition = _editorCaretPositionService.CaretPosition;
|
||||
if (caretPosition != _currentPositionRendered)
|
||||
{
|
||||
_currentPositionRendered = caretPosition;
|
||||
_label.Text = $"{_currentPositionRendered.Item1}:{_currentPositionRendered.Item2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2qyiyncm4sk5
|
||||
@@ -1,4 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://df55cl01wdfuv"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://df55cl01wdfuv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b2qyiyncm4sk5" path="res://Features/BottomBar/EditorLineCharDisplay.cs" id="1_ugdln"]
|
||||
|
||||
[node name="EditorLineCharDisplay" type="HBoxContainer"]
|
||||
anchors_preset = 15
|
||||
@@ -6,6 +8,7 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_ugdln")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
using SharpIDE.Application.Features.FileWatching;
|
||||
@@ -32,6 +33,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
public delegate void CodeFixesRequestedEventHandler();
|
||||
|
||||
private int _currentLine;
|
||||
private int _currentCol;
|
||||
private int _selectionStartCol;
|
||||
private int _selectionEndCol;
|
||||
|
||||
@@ -58,6 +60,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
[Inject] private readonly FileChangedService _fileChangedService = null!;
|
||||
[Inject] private readonly IdeApplyCompletionService _ideApplyCompletionService = null!;
|
||||
[Inject] private readonly IdeNavigationHistoryService _navigationHistoryService = null!;
|
||||
[Inject] private readonly EditorCaretPositionService _editorCaretPositionService = null!;
|
||||
|
||||
private readonly List<string> _codeCompletionTriggers =
|
||||
[
|
||||
@@ -85,6 +88,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
BreakpointToggled += OnBreakpointToggled;
|
||||
CaretChanged += OnCaretChanged;
|
||||
TextChanged += OnTextChanged;
|
||||
FocusEntered += OnFocusEntered;
|
||||
SymbolHovered += OnSymbolHovered;
|
||||
SymbolValidate += OnSymbolValidate;
|
||||
SymbolLookup += OnSymbolLookup;
|
||||
@@ -175,6 +179,12 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
GlobalEvents.Instance.SolutionAltered.Unsubscribe(OnSolutionAltered);
|
||||
if (_currentFile is not null) _openTabsFileManager.CloseFile(_currentFile);
|
||||
}
|
||||
|
||||
private void OnFocusEntered()
|
||||
{
|
||||
// The selected tab changed, report the caret position
|
||||
_editorCaretPositionService.CaretPosition = GetCaretPosition();
|
||||
}
|
||||
|
||||
private async void OnBreakpointToggled(long line)
|
||||
{
|
||||
@@ -207,6 +217,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
_selectionStartCol = GetSelectionFromColumn();
|
||||
_selectionEndCol = GetSelectionToColumn();
|
||||
_currentLine = GetCaretLine();
|
||||
_currentCol = GetCaretColumn();
|
||||
// GD.Print($"Selection changed to line {_currentLine}, start {_selectionStartCol}, end {_selectionEndCol}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user