예제 #1
0
 /// <summary>
 /// Creates a new AnchorSegment that creates new anchors.
 /// </summary>
 public AnchorSegment(TextDocument document, int offset, int length)
 {
     _start = document?.CreateAnchor(offset) ?? throw new ArgumentNullException(nameof(document));
     _start.SurviveDeletion = true;
     _start.MovementType    = AnchorMovementType.AfterInsertion;
     _end = document.CreateAnchor(offset + length);
     _end.SurviveDeletion = true;
     _end.MovementType    = AnchorMovementType.BeforeInsertion;
 }
예제 #2
0
        public void AnchorInEmptyDocument()
        {
            TextAnchor a1 = document.CreateAnchor(0);
            TextAnchor a2 = document.CreateAnchor(0);

            a1.MovementType = AnchorMovementType.BeforeInsertion;
            a2.MovementType = AnchorMovementType.AfterInsertion;
            Assert.AreEqual(0, a1.Offset);
            Assert.AreEqual(0, a2.Offset);
            document.Insert(0, "x");
            Assert.AreEqual(0, a1.Offset);
            Assert.AreEqual(1, a2.Offset);
        }