AvalonStudio.TextEditor.Document.TextAnchorTree.CreateAnchor C# (CSharp) 메소드

CreateAnchor() 공개 메소드

public CreateAnchor ( int offset ) : TextAnchor
offset int
리턴 TextAnchor
		public TextAnchor CreateAnchor(int offset)
		{
			Log("CreateAnchor(" + offset + ")");
			var 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
				var 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;
		}

Usage Example

예제 #1
0
 /// <summary>
 ///     Creates a new <see cref="TextAnchor" /> at the specified offset.
 /// </summary>
 /// <inheritdoc cref="TextAnchor" select="remarks|example" />
 public TextAnchor CreateAnchor(int offset)
 {
     VerifyAccess();
     if (offset < 0 || offset > rope.Length)
     {
         throw new ArgumentOutOfRangeException("offset", offset,
                                               "0 <= offset <= " + rope.Length.ToString(CultureInfo.InvariantCulture));
     }
     return(anchorTree.CreateAnchor(offset));
 }