   #
   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 typeof position isnt "number"
+      throw new Error 'Expected a number as first parameter'
+    if words.constructor isnt Array
+      throw new Error 'Expected a string array as second parameter'
     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
+      after = [new Word ' '].concat(@getWords(position))
+      before = @getWords(0, Math.max(position-1, 0)).append(new Word ' ')
+      if position == 0
+        before = []
+      else
+        before = @_rte.words[..position-1]
+      after = @_rte.words[position..]
+      @_rte.words = before.concat(words).concat(after)
+      # @updateInsertWords(position, words.length)
     else
       throw new Error 'Index #{position} out of bound in word list'
 

    # TODO


  # @overload deleteWords (start, end)
  # Delete all the words between start and end
  #
  # @param [Integer] start position of first word to delete
  # @param [Integer] end position of last word to delete
  #
  # @overload deleteWords (position)
  # Delete the word at position
  #
  # @param [Integer] position position the word to delete
  deleteWords: (start, end) ->
    if _.isUndefined(end)
      end = start+1

    if start <= end
      @_rte.words.splice(start, end-start)

  # Merge two words at position
  #

_ = require 'underscore'
# XRegExp = require('xregexp').XRegExp
WordRegExp = /\S+\s*/g
PreSpacesRegExp = /^\s+/
# Simple class that contains a word and links to the selections pointing
# to it
class Word
