       else if delta.insert?
         end = position + delta.insert.length
         selection = new Selection position, end, @
-        @insert(selection, delta.insert)
+        @insert selection, delta.insert
         position = end
       else
         throw new Error "Unknown operation"

    index = sel.startPos.word   #position to work from
    pos = sel.startPos.pos

    wordsToInsert = content.match /\w+ +/g
    preSpaces = content.search /^ +/

    currWord = @getWord index

    # Get spaces of next input and append them to last word to insert
    if index < @_rte.words.length - 1 and pos == (currWord.length - 1)
      nextWord = @getWord (index+1)
      preSpaces = nextWord.search /^ +/
      if preSpaces > -1         # add them to current word
        @setWord (index+1) nextWord.substring(preSpaces)
        last = _.last(wordsToInsert) + nextWord.substring(0, preSpaces)
        wordsToInsert[wordsToInsert.length-1] = last
    else if pos < (currWord.length - 1)
      nextWord = currWord.substring(pos)
      preSpaces = nextWord.search /^ +/
      if preSpaces > -1
        if not preSpaces == (nextWord.length-1)
          @insertWord (index+1) nextWord.substring(preSpaces)
        last = _.last(wordsToInsert) + nextWord.substring(0, preSpaces)
        wordsToInsert[wordsToInsert.length-1] = last

    # Add the spaces at beginning of input string to previous word
    # if any, or create an empty one
    if preSpaces > -1
      if pos == 0
        if index == 0
          emptyWord = new Word content.substring(0, preSpaces)
          @insertWord 0, emptyWord
        else
          # update previous word
          prevWord = @getWord (index-1)
          prevWord += content.substring(0, preSpaces)
          @setWord (index-1), prevWord


  split: (n) ->

  #
  insertWords: (position, words)->
    # TODO: update selections
    if not _.isNumber position
      throw new Error "Expected a number as first parameter, got #{position}"
    if not _.isArray words
      throw new Error "Expected a string array as second parameter, got #{words}"
    if 0 <= position <= @_rte.words.length
      wordsObj = (new Word w for w in words)
      console.log "splcing!", wordsObj

      left = @_rte.words.slice(0, position)
      right = @_rte.words.slice(position)
      console.log left, right
      @_rte.words = left.concat(wordsObj).concat(right)

      console.log @_rte.words
    else
      throw new Error 'Index #{position} out of bound in word list'

