mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-02 13:16:35 -05:00
fix a string truncation undo/redo bug. Make it possible to backspace in a string segment in an array. Make it possible to backspace multiple times in a string.
This commit is contained in:
@@ -355,10 +355,21 @@ namespace HavenSoft.Gen3Hex.Core.ViewModels {
|
||||
|
||||
run = Model.GetNextRun(index - 1);
|
||||
if (run is PCSRun pcs) {
|
||||
for (int i = index - 1; i < run.Start + run.Length; i++) Model[i] = 0xFF;
|
||||
for (int i = index - 1; i < run.Start + run.Length; i++) history.CurrentChange.ChangeData(Model, i, 0xFF);
|
||||
var length = PCSString.ReadString(Model, run.Start, true);
|
||||
Model.ObserveRunWritten(history.CurrentChange, new PCSRun(run.Start, length, run.PointerSources));
|
||||
RefreshBackingData();
|
||||
SilentScroll(index - 1);
|
||||
} else if (run is ArrayRun array) {
|
||||
var offsets = array.ConvertByteOffsetToArrayOffset(index - 1);
|
||||
if (array.ElementContent[offsets.SegmentIndex].Type == ElementContentType.PCS) {
|
||||
for (int i = index - 1; i < offsets.SegmentStart + array.ElementContent[offsets.SegmentIndex].Length; i++) history.CurrentChange.ChangeData(Model, i, 0x00);
|
||||
history.CurrentChange.ChangeData(Model, index - 1, 0xFF);
|
||||
RefreshBackingData();
|
||||
SilentScroll(index - 1);
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
} else if (run.Start <= index - 1 && run.Start + run.Length > index - 1) {
|
||||
// I want to do a backspace at the end of this run
|
||||
SelectionStart = scroll.DataIndexToViewPoint(run.Start);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using HavenSoft.Gen3Hex.Core.Models;
|
||||
using HavenSoft.Gen3Hex.Core;
|
||||
using HavenSoft.Gen3Hex.Core.Models;
|
||||
using HavenSoft.Gen3Hex.Core.ViewModels;
|
||||
using HavenSoft.Gen3Hex.Core.ViewModels.DataFormats;
|
||||
using System;
|
||||
@@ -315,5 +316,25 @@ namespace HavenSoft.Gen3Hex.Tests {
|
||||
var anchor = (Anchor)viewPort[8, 0].Format;
|
||||
Assert.IsType<PCS>(anchor.OriginalFormat);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanUndoStringTruncate() {
|
||||
var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
|
||||
var bytes = PCSString.Convert("Hello World!").ToArray();
|
||||
Array.Copy(bytes, 0, buffer, 0x08, bytes.Length);
|
||||
buffer[0] = 0x08;
|
||||
buffer[1] = 0x00;
|
||||
buffer[2] = 0x00;
|
||||
buffer[3] = 0x08;
|
||||
var model = new PointerAndStringModel(buffer);
|
||||
var viewPort = new ViewPort(new LoadedFile("test.txt", buffer), model) { Width = 0x10, Height = 0x10 };
|
||||
|
||||
viewPort.SelectionStart = new Point(0x0C, 0);
|
||||
viewPort.Edit(ConsoleKey.Backspace);
|
||||
viewPort.Undo.Execute();
|
||||
|
||||
Assert.Equal(13, model.GetNextRun(0x08).Length);
|
||||
Assert.Equal("\"Hello World!\"", ((PCS)viewPort[0x0C, 0].Format).FullString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user