예제 #1
0
 public TextAnchor CreateAnchor(int offset)
 {
     Log("CreateAnchor(" + offset + ")");
     TextAnchor anchor = new TextAnchor(document);
     anchor.node = new TextAnchorNode(anchor);
     if (root == null) {
         // creating the first text anchor
         root = anchor.node;
         root.totalLength = root.length = offset;
     } else if (offset >= root.totalLength) {
         // append anchor at end of tree
         anchor.node.totalLength = anchor.node.length = offset - root.totalLength;
         InsertAsRight(root.RightMost, anchor.node);
     } else {
         // insert anchor in middle of tree
         TextAnchorNode n = FindNode(ref offset);
         Debug.Assert(offset < n.length);
         // split segment 'n' at offset
         anchor.node.totalLength = anchor.node.length = offset;
         n.length -= offset;
         InsertBefore(n, anchor.node);
     }
     DeleteMarkedNodes();
     return anchor;
 }
예제 #2
0
 private void SetTextAnchor(int offset)
 {
     if(textAnchor != null)
         textAnchor.Deleted -= OnAnchorDeleted;
     textAnchor = Document.CreateAnchor(offset);
     textAnchor.Deleted += OnAnchorDeleted;
 }
예제 #3
0
        internal int totalLength; // totalLength = length + left.totalLength + right.totalLength

        #endregion Fields

        #region Constructors

        public TextAnchorNode(TextAnchor anchor)
            : base(anchor)
        {
        }