fix script formatting bug

formatting a script should not remove inner anchors
This commit is contained in:
haven1433 2022-10-13 07:06:21 -05:00
parent 2a5f36ee6f
commit a0254ef8ea
2 changed files with 30 additions and 1 deletions

View File

@ -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<XSERun>(CurrentChange, Model, address);

View File

@ -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<PointerRun>(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<PointerRun>(Model.GetNextRun(5));
Model.ResolveConflicts();
}
}
}