           @endContainer = splitText(@endContainer, @endOffset)
           @endOffset = 0
 
-    if @startContainer.nodeType is TEXT_NODE
+    if isTextNode(@startContainer)
       if 0 < @startOffset < @startContainer.length
         if @commonAncestorContainer is @startContainer
           @commonAncestorContainer = @commonAncestorContainer.parentNode

    # Get (a copy of) the boundaries of the range.
    {startContainer, startOffset, endContainer, endOffset} = this

    # Move the start container to the last leaf before any sibling boundary.
    # All children of the start container will fall within the range.
    while startContainer.childNodes.length and startOffset > 0
      startContainer = startContainer.childNodes[startOffset-1]
      startOffset = startContainer.length or startContainer.childNodes.length

    # Find the first TextNode not excluded by the start offset.
    node = startContainer
    while node? and node = firstLeaf(node)
      if node.nodeType is TEXT_NODE
        if not (node is startContainer and startOffset isnt 0)
          start = node
          break

      node = nextBranch(commonAncestor, node)

    # Move the end container to the first leaf before any sibling boundary.
    # All children of the end container will fall within the range.
    while endOffset < endContainer.childNodes.length
      endContainer = endContainer.childNodes[endOffset]
      endOffset = 0

    # Find the last TextNode not excluded by the end offset.
    node = endContainer
    while node? and node = lastLeaf(node)
      if node.nodeType is TEXT_NODE
        if not (node is endContainer and endOffset is 0)
          end = node
          break

      node = previousBranch(commonAncestor, node)

    return new NormalizedRange({commonAncestor, start, end})


    document = bounds.ownerDocument

    if not contains(bounds, @start)
      @start = findNode(firstLeaf(bounds), bounds, isTextNode, postFirst)

    if not contains(bounds, @end)
      @end = findNode(lastLeaf(bounds), bounds, isTextNode, postLast)

    return null unless @start and @end

