Fix table tool: streams should not have leading '+' on each line

This commit is contained in:
Benjamin Popp 2020-05-06 21:08:52 -05:00
parent 90dc561e2e
commit c87c6afca2
3 changed files with 16 additions and 8 deletions

View File

@ -94,7 +94,15 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
public string SerializeRun() {
var builder = new StringBuilder();
AppendTo(model, builder, Start, ElementLength * ElementCount);
return builder.ToString();
var lines = builder.ToString().Split(Environment.NewLine);
// AppendTo is used in copy/paste scenarios, and includes the required '+' to work in that case.
// strip the '+', as it's not needed for stream serialization, which uses newlines instead.
return string.Join(Environment.NewLine, lines.Select(line => {
if (line.Length == 0) return line;
if (line[0] != ArrayRun.ExtendArray) return line;
return line.Substring(1);
}).ToArray());
}
public IStreamRun DeserializeRun(string content, ModelDelta token) {

View File

@ -66,9 +66,9 @@ namespace HavenSoft.HexManiac.Tests {
ViewPort.Edit("00 01 02 03 FF ^bob CC @00 ^table[value.]!FF ");
ViewPort.Tools.SelectedIndex = ViewPort.Tools.IndexOf(ViewPort.Tools.StringTool);
Assert.Equal(@"0
+1
+2
+3", ViewPort.Tools.StringTool.Content);
1
2
3", ViewPort.Tools.StringTool.Content);
ViewPort.Tools.StringTool.Content = @"0
1

View File

@ -257,10 +257,10 @@ namespace HavenSoft.HexManiac.Tests {
// precondition: the format is as expected
Assert.Equal(@"255
+255
+255
+255
+255", segment.Content);
255
255
255
255", segment.Content);
// Act: change the content in a way that would change the length of a more dynamic stream.
segment.Content = "12";