diff --git a/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs index 8d201c3..258d803 100644 --- a/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs +++ b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs @@ -1,4 +1,5 @@ -using SharpIDE.Application.Features.Analysis; +using R3; +using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.SolutionDiscovery; namespace SharpIDE.Application.Features.NavigationHistory; @@ -9,12 +10,12 @@ public class IdeNavigationHistoryService // Using LinkedList for back stack to efficiently remove oldest entries private readonly LinkedList _backStack = new(); - private IdeNavigationLocation? _current; private readonly Stack _forwardStack = new(); public bool CanGoBack => _backStack.Count > 0; public bool CanGoForward => _forwardStack.Count > 0; - public IdeNavigationLocation? Current => _current; + public ReactiveProperty Current { get; private set; } = new(null); + public bool EnableRecording { get; set; } = false; public void StartRecording() => EnableRecording = true; @@ -23,40 +24,40 @@ public class IdeNavigationHistoryService { if (EnableRecording is false) return; var location = new IdeNavigationLocation(file, linePosition); - if (location == _current) + if (location == Current.Value) { // perhaps we filter out our forward and back navigations like this? return; } - if (_current is not null) + if (Current.Value is not null) { - _backStack.AddLast(_current); + _backStack.AddLast(Current.Value); if (_backStack.Count > MaxHistorySize) _backStack.RemoveFirst(); } - _current = location; + Current.Value = location; _forwardStack.Clear(); } public void GoBack() { if (!CanGoBack) throw new InvalidOperationException("Cannot go back, no history available."); - if (_current is not null) + if (Current.Value is not null) { - _forwardStack.Push(_current); + _forwardStack.Push(Current.Value); } - _current = _backStack.Last(); + Current.Value = _backStack.Last(); _backStack.RemoveLast(); } public void GoForward() { if (!CanGoForward) throw new InvalidOperationException("Cannot go forward, no history available."); - if (_current is not null) + if (Current.Value is not null) { - _backStack.AddLast(_current); + _backStack.AddLast(Current.Value); } - _current = _forwardStack.Pop(); + Current.Value = _forwardStack.Pop(); } } diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs index 699d476..516790f 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs @@ -376,7 +376,7 @@ public partial class SharpIdeCodeEdit : CodeEdit if (@event is InputEventMouseButton { Pressed: true } mouseEvent) { var (col, line) = GetLineColumnAtPos((Vector2I)mouseEvent.Position); - var current = _navigationHistoryService.Current; + var current = _navigationHistoryService.Current.Value; if (current!.File != _currentFile) throw new InvalidOperationException("Current navigation history file does not match the focused code editor file."); if (current.LinePosition.Line != line) // Only record a new navigation if the line has changed { diff --git a/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs b/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs index 93f2e41..57692de 100644 --- a/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs +++ b/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs @@ -17,26 +17,27 @@ public partial class ForwardBackwardButtonContainer : HBoxContainer _forwardButton = GetNode