     index = sel.startPos.word   #position to work from
     pos = sel.startPos.pos
 
-    wordsToInsert = content.match WordRegExp
     preSpaces = content.search PreSpacesRegExp
 
     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
+    # move the spaces to the previous word if a pos == 0
     if preSpaces > -1
       if pos == 0
-        if index == 0
-          emptyWord = new Word content.substring(0, preSpaces)
-          @insertWord 0, emptyWord
-          index = 1
-        else
-          # update previous word
-          prevWord = @getWord (index-1)
-          prevWord += content.substring(0, preSpaces)
-          @setWord (index-1), prevWord
-
-    @insertWords index, wordsToInsert
+        if index = 0
+          index += 1
+          @insertWord 0, (new Word '')
+        prevWord = @getWord (index-1)
+        prevWord += content.substring(0, preSpaces)
+        content = content.substring(preSpaces)
+
+    # insert the content at position
+    currWord = currWord.substring(0, pos) + content + currWord.substring(pos)
+
+    # cut the word
+    newWords = currWord.match WordRegExp
+    tmp = currWord.search PreSpacesRegExp
+    if (tmp) > - 1
+      newWords[0] = (currWord.substring 0, tmp) + newWords[0]
+    console.log newWords
+    @setWord index, newWords[0]
+    @insertWords index+1, newWords[1..]
+
+    # # Get spaces of next input and append them to last word to insert
+    # currWord = @getWord index
+    # if index < @_rte.words.length - 1 and pos == (currWord.length - 1)
+    #   console.log("e")
+    #   # last char of not last word
+    #   nextWord = @getWord (index+1)
+    #   preSpaces = nextWord.search /^ +/
+    #   if preSpaces > -1         # add them to current word
+    #     last = _.last(wordsToInsert) + nextWord.substring(0, preSpaces)
+    #     @setWord (index+1) nextWord.substring(preSpaces)
+    #     wordsToInsert[wordsToInsert.length-1] = last
+    # else if pos < (currWord.length - 1)
+    #   console.log("f")
+    #   endOfCurrWord = currWord.substring pos # can only be spaces or a word
+    #   lToInsert = _.last wordsToInsert
+    #   # if last word to insert ends with spaces and end of current word is a
+    #   # word, add end of current word to list of words to insert
+    #   if ((lToInsert.search PostSpacesRegExp) > -1) and
+    #      ((endOfCurrWord.search WordRegExp) > -1)
+    #     wordsToInsert.push endOfCurrWord
+    #   else
+    #     last = lToInsert + endOfCurrWord
+    #     wordsToInsert[wordsToInsert.length-1] = last
+
+    # # Add the spaces at beginning of input string to previous word
+    # if preSpaces > -1
+    #   if pos == 0
+    #     if index == 0
+    #       console.log("a")
+    #       # insert new word before
+    #       emptyWord = new Word content.substring(0, preSpaces)
+    #       @insertWord 0, emptyWord
+    #       index = 1
+    #     else
+    #       console.log("b")
+    #       # update previous word
+    #       prevWord = @getWord (index-1)
+    #       prevWord += content.substring(0, preSpaces)
+    #       @setWord (index-1), prevWord
+    #   else
+    #     console.log("c")
+    #     # update end of word at index
+    #     newWord = currWord.substring(0, pos) + content.substring(0, preSpaces)
+    #     @setWord index, newWord
+    #     index += 1
+    #     pos = 0
+    # else #
+    #   console.log("d")
+    #   prevWord = currWord.substring(pos)
+    #   # if prevWord has trailing spaces, index ++
+    #   postSpaces = prevWord.match PostSpacesRegExp
+    #   if postSpaces > -1
+    #     console.log(prevWord)
+    #     @setWord index, prevWord
+    #     index += 1
+    #     pos = 0
+    #   else # merge with first word to insert (and remove it from inserting queue)
+    #     console.log("d2")
+    #     first = wordsToInsert.pop(0)
+    #     newWord = currWord.substring(0, pos) + first
+    #     @setWord index, newWord
+    #     index += 1
+    #
+    # @insertWords index, wordsToInsert
 
   split: (n) ->
     word = @getWord n

        wlist[wlist.length-2] += ' '
      @insertWords n, wlist
    else
      console.log word
      console.log "Error here"


  # Relative jump from position

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