     # 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
-      if start - 1 < 0
-        before = []
-      else
-        before = @getWords(0, start-1)
-
-      @_rte.words = before.concat(@getWords(end))
-    @_rte.words
+      @_rte.words.splice(start, end-start)
 
   # Merge two words at position
   #

_ = require 'underscore'

splitWord = word ->
  word.match(/(^ +|)\W+ +/g)


buildWord = (word, prepend='', append='') ->
  tmp = word.match /(^ +|)\W+ +/g
  tmp2 = []

  if tmp.length == 1
    tmp2.push (new Word (prepend+tmp.pop()+append))
  else
    tmp2.push (new Word (prepend+tmp.pop(0)))
    while tmp.length > 1
      tmp2.push (new Word (tmp.pop(0) + ' '))

    tmp2.push (new Word (tmp.pop() + append + ' '))

  tmp2.reverse()

# Simple class that contains a word and links to the selections pointing
# to it
class Word

  #
  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'

