diff --git a/src/HexManiac.Core/ViewModels/Visitors/CompleteCellEdit.cs b/src/HexManiac.Core/ViewModels/Visitors/CompleteCellEdit.cs index cd2d44f8..27146759 100644 --- a/src/HexManiac.Core/ViewModels/Visitors/CompleteCellEdit.cs +++ b/src/HexManiac.Core/ViewModels/Visitors/CompleteCellEdit.cs @@ -564,7 +564,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Visitors { model.ClearFormat(token, newArray.Start, array.Length); } } - model.ClearFormat(token, newArray.Start, newArray.Length); + + // clear any anchors that would be added as inner-pointers + for (var nextRun = model.GetNextRun(newArray.Start); nextRun.Start < newArray.Start + newArray.Length; nextRun = model.GetNextRun(nextRun.Start + nextRun.Length)) { + if (nextRun.Start == newArray.Start) continue; + model.ClearAnchor(token, nextRun.Start, nextRun.Length); + } model.ObserveRunWritten(token, newArray); // if this run has pointers, those may have been cleared by some earlier update @@ -767,8 +772,18 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Visitors { ErrorText = "Cannot write constant with no name."; return; } + var addresses = Model.GetMatchedWords(constantName); + if (CurrentChange is not NoDataChangeDeltaModel && newValue == int.MinValue && addresses.Count > 0) { + var valueSource = (WordRun)Model.GetNextRun(addresses[0]); + int value = Model.ReadMultiByteValue(valueSource.Start, valueSource.Length); + value /= valueSource.MultOffset; + value -= valueSource.ValueOffset; + Model.WriteMultiByteValue(memoryLocation, byteCount, CurrentChange, (value + offset) * multOffset); + newValue = (value + offset) * multOffset; + } - var coreValue = (Model[memoryLocation] / multOffset) - offset; + // var coreValue = (Model[memoryLocation] / multOffset) - offset; + var coreValue = Model.ReadMultiByteValue(memoryLocation, byteCount) / multOffset - offset; if (newValue != int.MinValue) coreValue = newValue / multOffset - offset; var maxValue = Math.Pow(2, byteCount * 8) - 1; if (coreValue < 0) { diff --git a/src/HexManiac.Tests/ConstantTests.cs b/src/HexManiac.Tests/ConstantTests.cs index ec2e8290..62df29a1 100644 --- a/src/HexManiac.Tests/ConstantTests.cs +++ b/src/HexManiac.Tests/ConstantTests.cs @@ -28,12 +28,12 @@ namespace HavenSoft.HexManiac.Tests { } [Fact] - public void ConstantFormat_EnterNewConstantOnByteWithDifferentValue_OtherBytesChangeToMatchCurrentValue() { + public void ConstantFormat_EnterNewConstantOnByteWithDifferentValue_CurrentValueCHangesToMatchConstant() { ViewPort.Edit("@100 03 @100 .some.number+1 "); ViewPort.Edit("@000 .some.number "); - Assert.Equal(1, Model[0x100]); + Assert.Equal(2, Model[0]); } [Fact]