From 4da667f4da2c59752ec4a85bca6e2c8752b5f5fd Mon Sep 17 00:00:00 2001 From: Benjamin Popp Date: Sat, 29 Jun 2019 08:51:41 -0500 Subject: [PATCH] Make it possible to remove matched words --- src/HexManiac.Core/Models/PokemonModel.cs | 4 ++++ src/HexManiac.Tests/ArrayRunTests.cs | 24 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/HexManiac.Core/Models/PokemonModel.cs b/src/HexManiac.Core/Models/PokemonModel.cs index 6ea89110..fac4b866 100644 --- a/src/HexManiac.Core/Models/PokemonModel.cs +++ b/src/HexManiac.Core/Models/PokemonModel.cs @@ -748,6 +748,10 @@ namespace HavenSoft.HexManiac.Core.Models { if (run.Start >= start + length) return; if (run is PointerRun) ClearPointerFormat(null, changeToken, run.Start); if (run is ArrayRun arrayRun) ModifyAnchorsFromPointerArray(changeToken, arrayRun, ClearPointerFormat); + if (run is WordRun wordRun) { + changeToken.RemoveMatchedWord(wordRun.Start, wordRun.SourceArrayName); + matchedWords[wordRun.SourceArrayName].Remove(wordRun.Start); + } ClearAnchorFormat(changeToken, originalStart, run); diff --git a/src/HexManiac.Tests/ArrayRunTests.cs b/src/HexManiac.Tests/ArrayRunTests.cs index d9a92137..51d0b27d 100644 --- a/src/HexManiac.Tests/ArrayRunTests.cs +++ b/src/HexManiac.Tests/ArrayRunTests.cs @@ -1024,6 +1024,30 @@ namespace HavenSoft.HexManiac.Tests { Assert.Equal(5, length); } + [Fact] + public void CanRemoveLooseWordRuns() { + StandardSetup(out var data, out var model, out var viewPort); + viewPort.Edit("^table[a:: b::]4 "); // 0x20 bytes + + // add the format + viewPort.SelectionStart = new Point(0, 5); + viewPort.Edit("::table "); // should create a new 4-byte run that stays in sync with the table + + // remove the format + var items = viewPort.GetContextMenuItems(new Point(0, 5)); + var contextItem = items.Single(item => item.Text == "Clear Format"); + contextItem.Command.Execute(); + + // extend the table + viewPort.SelectionStart = new Point(0, 2); + viewPort.Edit("+"); + + // verify that the table was extended, but the value at 0x50 was NOT (no longer tied together) + Assert.Equal(5, ((ArrayRun)model.GetNextRun(0)).ElementCount); + var length = model.ReadValue(0x50); + Assert.Equal(4, length); + } + private static void StandardSetup(out byte[] data, out PokemonModel model, out ViewPort viewPort) { data = new byte[0x200]; model = new PokemonModel(data);