Make it possible to remove matched words

This commit is contained in:
Benjamin Popp
2019-06-29 08:51:41 -05:00
parent 117b77000d
commit 4da667f4da
2 changed files with 28 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);