         @deleteSel selection
 
       else if delta.insert?
-        end = position + delta.insert.length
-        selection = new Selection position, end, @
-        @insert selection, delta.insert
+        @insert position, delta.insert
         position += delta.insert.length
 
       else

_ = require 'underscore'

# XRegExp = require('xregexp').XRegExp
WordRegExp = /\S+\s*/g

    leftIndex = left.index @
    rightIndex = right.index @

    newLeft = left.word.substring 0, selection.leftPos
    newRight = right.word.substring selection.rightPos

    if left == right
      @setWord leftIndex, (newLeft + newRight)

      # delete the words in between
      @deleteWords leftIndex+1, rightIndex
    else
      @setWord leftIndex, newLeft
      @setWord rightIndex, newRight

      # delete the words in between
      @deleteWords leftIndex+1, rightIndex
      # merge
      @merge leftIndex

  # Insert text at position
  #
  # @param [Integer] position The position where to insert text
  # @param [String] content the content to insert
  #
  insert: (position, content)->
    if not (_.isNumber position)
      throw new Error "Expected an integer as first argument"
    if not (_.isString content)
      throw new Error "Expected a string as second argument"

    if content.length == 0
      return

    ret = relativeFromAbsolute position, @

    index = ret.word   #position to work from
    pos = ret.pos

    preSpaces = content.match PreSpacesRegExp
    currWord = @getWord(index).word
