fix script selection bug

if the script start changes and the script end doesn't change, we still need to update the script shown in the code tool.
This commit is contained in:
haven1433
2024-06-02 15:52:42 -05:00
parent 6968fffb89
commit 32bebb384b
2 changed files with 15 additions and 2 deletions

View File

@@ -110,7 +110,9 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
this.history = history;
this.messageTab = messageTab;
selection.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(selection.SelectionEnd)) {
if (e.PropertyName == nameof(selection.SelectionStart)) {
if (selection.SelectionStart == selection.SelectionEnd) UpdateContent();
} else if (e.PropertyName == nameof(selection.SelectionEnd)) {
UpdateContent();
}
};

View File

@@ -13,7 +13,7 @@ namespace HavenSoft.HexManiac.Tests {
public class CodeToolTests : BaseViewModelTestClass {
private CodeTool Tool => ViewPort.Tools.CodeTool;
private string EventScript {
get => ";".Join(Tool.Contents[0].Content.SplitLines().Select(line => line.Trim()));
get => ";".Join(Tool.Contents[0].Content.SplitLines().Where(line => !string.IsNullOrWhiteSpace(line)).Select(line => line.Trim()));
set {
Tool.Mode = CodeMode.Script;
Tool.Contents[0].Content = value.Replace(";", Environment.NewLine);
@@ -891,5 +891,16 @@ label2:;goto <000050>;end";
var expected = "21 00 40 07 00 06 01 10 00 72 08 02".ToByteArray();
Assert.All(expected.Length.Range(), i => Assert.Equal(expected[i], Model[i]));
}
[Fact]
public void EntireScriptSelected_SelectLastByte_ShownScriptUpdated() {
EventScript = "nop;end";
ViewPort.SelectionStart = new(0, 0);
ViewPort.SelectionEnd = new(1, 0);
ViewPort.SelectionStart = new(1, 0);
Assert.Equal("end", EventScript);
}
}
}