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; }
private void SetTextAnchor(int offset) { if(textAnchor != null) textAnchor.Deleted -= OnAnchorDeleted; textAnchor = Document.CreateAnchor(offset); textAnchor.Deleted += OnAnchorDeleted; }
internal int totalLength; // totalLength = length + left.totalLength + right.totalLength #endregion Fields #region Constructors public TextAnchorNode(TextAnchor anchor) : base(anchor) { }