diff --git a/src/HexManiac.Core/ViewModels/ViewPort.cs b/src/HexManiac.Core/ViewModels/ViewPort.cs index 77d195b2..07f061e4 100644 --- a/src/HexManiac.Core/ViewModels/ViewPort.cs +++ b/src/HexManiac.Core/ViewModels/ViewPort.cs @@ -2367,7 +2367,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels { Goto.Execute(addressText); Debug.Assert(scroll.DataIndex == address - address % 16); var length = tools.CodeTool.ScriptParser.GetScriptSegmentLength(Model, address); - Model.ClearFormat(CurrentChange, address, length - 1); + + // clear format in a way that won't remove inner-anchors, since some scripts point into other scripts + for (var run = Model.GetNextRun(address); run.Start < address + length; run = Model.GetNextRun(run.Start + run.Length)) { + Model.ClearFormat(CurrentChange, address, 1); + } using (ModelCacheScope.CreateScope(Model)) { tools.CodeTool.ScriptParser.FormatScript(CurrentChange, Model, address); diff --git a/src/HexManiac.Tests/CodeToolTests.cs b/src/HexManiac.Tests/CodeToolTests.cs index 3c9d5179..9053086d 100644 --- a/src/HexManiac.Tests/CodeToolTests.cs +++ b/src/HexManiac.Tests/CodeToolTests.cs @@ -141,5 +141,30 @@ namespace HavenSoft.HexManiac.Tests { Assert.Equal(4, Tool.Contents.Count); } + + [Fact] + public void ScriptWithInnerAnchor_AddScriptFormat_AnchorKept() { + Tool.Mode = CodeMode.Script; + EventScript = "lock;faceplayer;end"; + ViewPort.Edit("@010 <001>"); + + ViewPort.Goto.Execute(0); + ViewPort.Edit("^`xse`"); + + Assert.IsType(Model.GetNextRun(0x10)); + } + + [Fact] + public void ScriptWithInnerAnchor_AddPointerAtThatLocation_AnchorRemoved() { + Tool.Mode = CodeMode.Script; + EventScript = "lock;if1 = <100>;end"; + ViewPort.Edit("@010 <005>"); // points into the pointer + + ViewPort.Goto.Execute(0); + ViewPort.Edit("^`xse`"); + + Assert.IsType(Model.GetNextRun(5)); + Model.ResolveConflicts(); + } } }