don't allow writing nameless anchors with nothing pointing to them

This commit is contained in:
Haven1433 2022-08-17 22:31:15 -05:00
parent 762e719984
commit e26cf56a2b
2 changed files with 22 additions and 1 deletions

View File

@ -762,7 +762,18 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
}
if (run.Start <= index) {
var token = new NoDataChangeDeltaModel();
var errorInfo = PokemonModel.ApplyAnchor(Model, token, run.Start, AnchorText);
// During edits, typing `^` is allowed, and is used as a way to remove an anchor.
// When doing AnchorText edits, clearing the name/format when there are no pointers is an error.
ErrorInfo errorInfo = ErrorInfo.NoError;
if (AnchorText == AnchorStart.ToString() && run.PointerSources.Count == 0) {
errorInfo = new ErrorInfo("An anchor with nothing pointing to it must have a name.");
}
if (errorInfo == ErrorInfo.NoError) {
errorInfo = PokemonModel.ApplyAnchor(Model, token, run.Start, AnchorText);
}
if (errorInfo == ErrorInfo.NoError) {
OnError?.Invoke(this, string.Empty);
var newRun = Model.GetNextRun(index);

View File

@ -658,6 +658,16 @@ namespace HavenSoft.HexManiac.Tests {
Assert.True(ViewPort.ChangeHistory.IsSaved);
}
[Fact]
public void TextAnchor_ChangeToNoInfoAnchor_NoNameIsError() {
SetFullModel(0xFF);
ViewPort.Edit("^text\"\" ");
ViewPort.AnchorText = "^";
Assert.NotEmpty(Errors);
}
private void Write(IDataModel model, ref int i, string characters) {
foreach (var c in characters.ToCharArray())
model[i++] = (byte)PCSString.PCS.IndexOf(c.ToString());