Beispiel #1
0
 /// <summary>
 /// Returns a duplicate of the node on which this method was called.
 /// </summary>
 /// <param name="deep">
 /// Optional value: true if the children of the node should also be
 /// cloned, or false to clone only the specified node.
 /// </param>
 /// <returns>The duplicate node.</returns>
 public override INode Clone(Boolean deep = true)
 {
     var node = new TextNode(Owner, Data);
     CopyProperties(this, node, deep);
     return node;
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new text node with the content starting at the specified
        /// offset. Adds the new node to the DOM as a sibling. Truncates the
        /// current node.
        /// </summary>
        /// <param name="offset">
        /// The position where the split should occur.
        /// </param>
        /// <returns>The freshly created text node.</returns>
        public IText Split(Int32 offset)
        {
            var length = Length;

            if (offset > length)
                throw new DomException(DomError.IndexSizeError);

            var count = length - offset;
            var newData = Substring(offset, count);
            var newNode = new TextNode(Owner, newData);
            var parent = Parent;
            var owner = Owner;

            if (parent != null)
            {
                var index = this.Index();
                parent.InsertBefore(newNode, NextSibling);

                owner.ForEachRange(m => m.Head == this && m.Start > offset, m => m.StartWith(newNode, m.Start - offset));
                owner.ForEachRange(m => m.Tail == this && m.End > offset, m => m.EndWith(newNode, m.End - offset));
                owner.ForEachRange(m => m.Head == parent && m.Start == index + 1, m => m.StartWith(parent, m.Start + 1));
                owner.ForEachRange(m => m.Tail == parent && m.End == index + 1, m => m.StartWith(parent, m.End + 1));
            }

            Replace(offset, count, String.Empty);

            if (parent != null)
            {
                owner.ForEachRange(m => m.Head == this && m.Start > offset, m => m.StartWith(this, offset));
                owner.ForEachRange(m => m.Tail == this && m.End > offset, m => m.EndWith(this, offset));
            }

            return newNode;
        }
Beispiel #3
0
 public override INode Clone(Boolean deep = true)
 {
     var node = new TextNode(Owner, Data);
     CloneNode(node, deep);
     return node;
 }