diff --git a/src/HexManiac.Core/ViewModels/Tools/CodeTool.cs b/src/HexManiac.Core/ViewModels/Tools/CodeTool.cs index 1e0497f2..b52bb686 100644 --- a/src/HexManiac.Core/ViewModels/Tools/CodeTool.cs +++ b/src/HexManiac.Core/ViewModels/Tools/CodeTool.cs @@ -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(); } }; diff --git a/src/HexManiac.Tests/CodeToolTests.cs b/src/HexManiac.Tests/CodeToolTests.cs index 65d9ec13..b33cf193 100644 --- a/src/HexManiac.Tests/CodeToolTests.cs +++ b/src/HexManiac.Tests/CodeToolTests.cs @@ -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); + } } }