mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-01 20:56:36 -05:00
track cursor when changing text during script compiles
for example, when adding {} to the end of a script, or when changing ?????? to an actual address
This commit is contained in:
@@ -46,6 +46,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
public string CommentContent { get; private set; } = string.Empty;
|
||||
public string TextContent { get; private set; } = string.Empty;
|
||||
|
||||
public void PushCaretUpdate(int index) {
|
||||
CaretIndex = index;
|
||||
RequestCaretMove.Raise(this);
|
||||
}
|
||||
|
||||
private void UpdateLayers() {
|
||||
if (content.Length == 0) {
|
||||
PlainContent = AccentContent =
|
||||
|
||||
@@ -371,6 +371,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
|
||||
var oldScripts = parser.CollectScripts(model, start);
|
||||
var originalCodeContent = codeContent;
|
||||
var code = parser.Compile(history.CurrentChange, model, start, ref codeContent, out var movedData);
|
||||
if (originalCodeContent != codeContent) body.SaveCaret();
|
||||
if (code == null) {
|
||||
return;
|
||||
}
|
||||
@@ -528,6 +529,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
|
||||
public int CaretPosition {
|
||||
get => Editor.CaretIndex;
|
||||
set {
|
||||
if (savedCaret >= 0) {
|
||||
value = savedCaret;
|
||||
savedCaret = -1;
|
||||
Editor.PushCaretUpdate(value);
|
||||
return;
|
||||
}
|
||||
if (Editor.CaretIndex == value) return;
|
||||
var lines = Content.Split('\r', '\n').ToList();
|
||||
var contentBoundaryCount = 0;
|
||||
@@ -571,6 +578,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
|
||||
NotifyPropertyChanged(nameof(CaretPosition));
|
||||
});
|
||||
}
|
||||
|
||||
private int savedCaret = -1;
|
||||
public void SaveCaret() {
|
||||
savedCaret = CaretPosition + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public record HelpContext(string Line, int Index);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using HavenSoft.HexManiac.Core.ViewModels;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
@@ -40,7 +39,6 @@ namespace HavenSoft.HexManiac.WPF.Controls {
|
||||
public TextEditor() {
|
||||
InitializeComponent();
|
||||
TransparentLayer.SelectionChanged += (sender, e) => {
|
||||
// if (ViewModel != null) ViewModel.CaretIndex = TransparentLayer.SelectionStart;
|
||||
SelectionChanged?.Invoke(this, e);
|
||||
};
|
||||
DataContextChanged += HandleDataContextChanged;
|
||||
|
||||
Reference in New Issue
Block a user