mirror of
https://github.com/4sval/FModel.git
synced 2026-09-13 20:16:38 -05:00
go to last cursor location
This commit is contained in:
34
FModel/Framework/NavigationList.cs
Normal file
34
FModel/Framework/NavigationList.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FModel.Framework
|
||||
{
|
||||
public class NavigationList<T> : List<T>
|
||||
{
|
||||
private int _currentIndex = 0;
|
||||
public int CurrentIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentIndex > Count - 1) { _currentIndex = Count - 1; }
|
||||
if (_currentIndex < 0) { _currentIndex = 0; }
|
||||
return _currentIndex;
|
||||
}
|
||||
set { _currentIndex = value; }
|
||||
}
|
||||
|
||||
public T MoveNext
|
||||
{
|
||||
get { _currentIndex++; return this[CurrentIndex]; }
|
||||
}
|
||||
|
||||
public T MovePrevious
|
||||
{
|
||||
get { _currentIndex--; return this[CurrentIndex]; }
|
||||
}
|
||||
|
||||
public T Current
|
||||
{
|
||||
get { return this[CurrentIndex]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,6 +357,7 @@ namespace FModel.ViewModels
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
var hotfixes = ApplicationService.ApiEndpointView.BenbotApi.GetHotfixes(cancellationToken, Provider.GetLanguageCode(UserSettings.Default.AssetLanguage));
|
||||
if (hotfixes == null) return;
|
||||
|
||||
foreach (var entries in hotfixes)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<Grid Grid.Row="0" Margin="3 0" HorizontalAlignment="Right" Width="500">
|
||||
<Grid.Style>
|
||||
<Style TargetType="{x:Type Grid}">
|
||||
@@ -34,7 +34,7 @@
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
<Grid Grid.Column="0" ZIndex="1" HorizontalAlignment="Left" Margin="5 2 0 0">
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
@@ -113,6 +113,6 @@
|
||||
<avalonEdit:TextEditor x:Name="MyAvalonEditor" Grid.Row="0" Grid.RowSpan="2" SyntaxHighlighting="{Binding Highlighter}" Document="{Binding Document}"
|
||||
FontFamily="Consolas" FontSize="{Binding FontSize}" IsReadOnly="True" ShowLineNumbers="True" Foreground="#DAE5F2"
|
||||
Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" PreviewMouseWheel="OnPreviewMouseWheel"
|
||||
TextChanged="OnTextChanged" MouseHover="OnMouseHover" MouseHoverStopped="OnMouseHoverStopped" />
|
||||
TextChanged="OnTextChanged" MouseHover="OnMouseHover" MouseHoverStopped="OnMouseHoverStopped" PreviewMouseUp="OnMouseRelease" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using FModel.Extensions;
|
||||
using FModel.Framework;
|
||||
using FModel.ViewModels;
|
||||
using ICSharpCode.AvalonEdit;
|
||||
using SkiaSharp;
|
||||
@@ -20,12 +22,14 @@ namespace FModel.Views.Resources.Controls
|
||||
private readonly Regex _hexColorRegex = new("\"Hex\": \"(?'target'[0-9A-Fa-f]{3,8})\"$",
|
||||
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||
private readonly System.Windows.Controls.ToolTip _toolTip = new();
|
||||
private readonly NavigationList<int> _caretList = new();
|
||||
private bool _ignoreCaret = true;
|
||||
|
||||
public AvalonEditor()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(NavigationCommands.Search, (_, e) => FindNext(e.Parameter != null)));
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
YesWeEditor = MyAvalonEditor;
|
||||
YesWeSearch = WpfSuckMyDick;
|
||||
MyAvalonEditor.TextArea.TextView.ElementGenerators.Add(new GamePathElementGenerator());
|
||||
@@ -49,6 +53,23 @@ namespace FModel.Views.Resources.Controls
|
||||
FindNext();
|
||||
dc.SearchUp = old;
|
||||
break;
|
||||
case Key.System: // Alt
|
||||
if (Keyboard.IsKeyDown(Key.Left))
|
||||
{
|
||||
if (_caretList.Count == 0)
|
||||
return;
|
||||
var movep = _caretList.MovePrevious;
|
||||
MyAvalonEditor.CaretOffset = movep;
|
||||
MyAvalonEditor.TextArea.Caret.BringCaretToView();
|
||||
} else if ((Keyboard.IsKeyDown(Key.Right)))
|
||||
{
|
||||
if (_caretList.Count == 0)
|
||||
return;
|
||||
var move = _caretList.MoveNext;
|
||||
MyAvalonEditor.CaretOffset = move;
|
||||
MyAvalonEditor.TextArea.Caret.BringCaretToView();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +109,8 @@ namespace FModel.Views.Resources.Controls
|
||||
if (sender is not TextEditor avalonEditor || DataContext is not TabItem tabItem ||
|
||||
avalonEditor.Document == null || string.IsNullOrEmpty(avalonEditor.Document.Text))
|
||||
return;
|
||||
|
||||
_caretList.Clear();
|
||||
_ignoreCaret = true;
|
||||
avalonEditor.Document.FileName = tabItem.Directory + '/' + tabItem.Header.SubstringBeforeLast('.');
|
||||
if (!tabItem.ShouldScroll) return;
|
||||
|
||||
@@ -102,7 +124,7 @@ namespace FModel.Views.Resources.Controls
|
||||
{
|
||||
if (DataContext is not TabItem tabItem || Keyboard.Modifiers != ModifierKeys.Control)
|
||||
return;
|
||||
|
||||
|
||||
var fontSize = tabItem.FontSize + e.Delta / 50.0;
|
||||
tabItem.FontSize = fontSize switch
|
||||
{
|
||||
@@ -186,5 +208,22 @@ namespace FModel.Views.Resources.Controls
|
||||
{
|
||||
((TabItem) DataContext).HasSearchOpen = false;
|
||||
}
|
||||
|
||||
private void SaveCaretLoc(int offset)
|
||||
{
|
||||
if (_ignoreCaret) { _ignoreCaret = false; return;} // first always point to the end of the file for some reason
|
||||
if (_caretList.Count >= 10)
|
||||
_caretList.RemoveAt(0);
|
||||
if (!_caretList.Contains(offset))
|
||||
{
|
||||
_caretList.Add(offset);
|
||||
_caretList.CurrentIndex = _caretList.Count-1;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseRelease(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
SaveCaretLoc(MyAvalonEditor.CaretOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user