public void FixUpFirstPartOfDelimiter() { document.Text = "a\n\nb"; document.Replace(1, 1, "\r"); Assert.AreEqual("a\r\nb", document.Text); CheckDocumentLines("a", "b"); }
public void ShortReplacements() { char[] chars = { 'a', 'b', '\r', '\n' }; char[] buffer = new char[20]; for (int i = 0; i < 2500; i++) { int offset = rnd.Next(0, document.TextLength); int length = rnd.Next(0, document.TextLength - offset); int newTextLength = rnd.Next(0, 20); for (int j = 0; j < newTextLength; j++) { buffer[j] = chars[rnd.Next(0, chars.Length)]; } document.Replace(offset, length, new string(buffer, 0, newTextLength)); CheckLines(); } }
public void MoveAnchorsDuringReplace() { document.Text = "abcd"; TextAnchor start = document.CreateAnchor(1); TextAnchor middleDeletable = document.CreateAnchor(2); TextAnchor middleSurvivorLeft = document.CreateAnchor(2); middleSurvivorLeft.SurviveDeletion = true; middleSurvivorLeft.MovementType = AnchorMovementType.BeforeInsertion; TextAnchor middleSurvivorRight = document.CreateAnchor(2); middleSurvivorRight.SurviveDeletion = true; middleSurvivorRight.MovementType = AnchorMovementType.AfterInsertion; TextAnchor end = document.CreateAnchor(3); document.Replace(1, 2, "BxC"); Assert.AreEqual(1, start.Offset); Assert.IsTrue(middleDeletable.IsDeleted); Assert.AreEqual(1, middleSurvivorLeft.Offset); Assert.AreEqual(4, middleSurvivorRight.Offset); Assert.AreEqual(4, end.Offset); }
public void BackwardChanges() { TextDocument document = new TextDocument("initial text"); ITextSource snapshot1 = document.CreateSnapshot(); document.Replace(0, 7, "nw"); document.Insert(1, "e"); ITextSource snapshot2 = document.CreateSnapshot(); Assert.AreEqual(1, snapshot2.Version.CompareAge(snapshot1.Version)); TextChangeEventArgs[] arr = snapshot2.Version.GetChangesTo(snapshot1.Version).ToArray(); Assert.AreEqual(2, arr.Length); Assert.AreEqual("", arr[0].InsertedText.Text); Assert.AreEqual("initial", arr[1].InsertedText.Text); Assert.AreEqual("initial text", snapshot1.Text); Assert.AreEqual("new text", snapshot2.Text); }
public void Undo() { var map = _change.OffsetChangeMapOrNull; _document.Replace(_change.Offset, _change.InsertionLength, _change.RemovedText, map?.Invert()); }