 
         if @startContainer is @endContainer
           @commonAncestorContainer = @startContainer.parentNode
-          @startContainer = @startContainer.splitText(@startOffset)
+          @startContainer = splitText(@startContainer, @startOffset)
 
           if @startOffset <= @endOffset
             @endContainer = @startContainer


          @startOffset = 0
        else
          @startContainer = @startContainer.splitText(@startOffset)
          @startOffset = 0

  # Public: Normalize the start and end to TextNode boundaries.

# https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
ELEMENT_NODE = 1
TEXT_NODE = 3


insertAfter = (node, referenceNode) ->
  parent = referenceNode.parentNode
  next = referenceNode.nextSibling
  if next then return parent.insertBefore(node, next)
  return parent.appendChild(node)


# https://github.com/Raynos/DOM-shim/issues/11
splitText = (node, offset) ->
  tail = node.cloneNode(false)
  tail.deleteData(0, offset)
  node.deleteData(offset, node.length - offset)
  return insertAfter(tail, node)


# Public: Creates a wrapper around a range object obtained from a DOMSelection.
