diff --git a/SkEditor/Controls/MainMenuControl.axaml b/SkEditor/Controls/MainMenuControl.axaml index 9fc2852c..911af87d 100644 --- a/SkEditor/Controls/MainMenuControl.axaml +++ b/SkEditor/Controls/MainMenuControl.axaml @@ -121,6 +121,11 @@ + + + + + diff --git a/SkEditor/Controls/MainMenuControl.axaml.cs b/SkEditor/Controls/MainMenuControl.axaml.cs index 48a7f2bb..36977813 100644 --- a/SkEditor/Controls/MainMenuControl.axaml.cs +++ b/SkEditor/Controls/MainMenuControl.axaml.cs @@ -56,6 +56,7 @@ private void AssignCommands() MenuItemDuplicate.Command = new RelayCommand(() => CustomCommandsHandler.OnDuplicateCommandExecuted(ApiVault.Get().GetTextEditor().TextArea)); MenuItemComment.Command = new RelayCommand(() => CustomCommandsHandler.OnCommentCommandExecuted(ApiVault.Get().GetTextEditor().TextArea)); + MenuItemGoToLine.Command = new RelayCommand(() => new GoToLine().ShowDialog(ApiVault.Get().GetMainWindow())); MenuItemRefreshSyntax.Command = new RelayCommand(async () => await SyntaxLoader.RefreshSyntaxAsync()); diff --git a/SkEditor/Languages/English.xaml b/SkEditor/Languages/English.xaml index 00250dba..25d25a22 100644 --- a/SkEditor/Languages/English.xaml +++ b/SkEditor/Languages/English.xaml @@ -46,6 +46,7 @@ Duplicate Comment Delete + Go to line Documentation @@ -365,5 +366,9 @@ Disable Enable + + Go to line + Go + \ No newline at end of file diff --git a/SkEditor/Languages/Polish.xaml b/SkEditor/Languages/Polish.xaml index 0a6d775b..714cc8f8 100644 --- a/SkEditor/Languages/Polish.xaml +++ b/SkEditor/Languages/Polish.xaml @@ -46,6 +46,7 @@ Duplikuj Zakomentuj Usuń + Przejdź do linii Dokumentacja @@ -293,5 +294,9 @@ Wyłącz Włącz + + Przejdź do linii + Idź + \ No newline at end of file diff --git a/SkEditor/Utilities/Editor/GoToLine.axaml b/SkEditor/Utilities/Editor/GoToLine.axaml new file mode 100644 index 00000000..41bded73 --- /dev/null +++ b/SkEditor/Utilities/Editor/GoToLine.axaml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/SkEditor/Utilities/Editor/GoToLine.axaml.cs b/SkEditor/Utilities/Editor/GoToLine.axaml.cs new file mode 100644 index 00000000..fe4e3622 --- /dev/null +++ b/SkEditor/Utilities/Editor/GoToLine.axaml.cs @@ -0,0 +1,45 @@ +using System; +using AvaloniaEdit; +using AvaloniaEdit.Document; +using CommunityToolkit.Mvvm.Input; +using FluentAvalonia.UI.Windowing; +using SkEditor.API; + +namespace SkEditor.Utilities.Editor; +public partial class GoToLine : AppWindow +{ + + public GoToLine() + { + InitializeComponent(); + GoToLineInput.Loaded += (sender, e) => GoToLineInput.Focus(); + GoToLineInput.TextChanged += (_, _) => UpdateInput(); + GoToLineButton.Command = new RelayCommand(Execute); + + } + + private void Execute() + { + if (string.IsNullOrWhiteSpace(GoToLineInput.Text)) return; + + TextEditor editor = ApiVault.Get().GetTextEditor(); + if (!int.TryParse(GoToLineInput.Text, out int lineNumber)) return; + DocumentLine line = editor.Document.GetLineByNumber(lineNumber); + editor.ScrollTo(line.LineNumber, 0); + editor.Focus(); + editor.CaretOffset = line.Offset; + Close(); + } + + private void UpdateInput() + { + TextEditor editor = ApiVault.Get().GetTextEditor(); + int documentLines = editor.Document.LineCount; + if (!int.TryParse(GoToLineInput.Text, out int line)) { + GoToLineInput.Text = ""; + return; + }; + line = Math.Clamp(line, 1, documentLines); + GoToLineInput.Text = line.ToString(); + } +}