 
   # Merge two words at position
   #
-  # @param [Integer] n position of word where to perform merge. The merge will be done with the word at right (if any)
-  #
-  merge: (n) ->
-    if 0 <= n < @_rte.words.length
-      w = @getWord(n).trimRight()
-      @deleteWords n
-      @insert {startPos: {word: n, pos:0}}, w
+  # @param [Integer] n position of word where to perform merge. The merge will
+  #  be done with the word at right (if any)
+  #
+  merge: (index) ->
+    if 0 <= index < @_rte.words.length
+      w = @getWord(index).trimRight()
+      @deleteWords index
+      @insert {startPos: {word: index, pos:0}}, w
     else
       throw new Error "Impossible to merge"
 

  #
  isValid: ->
    @startPos.lt(@endPos)


# Class describing the Rich Text Editor type
#
class Rte
  # @property [Options] _rte the RTE object
  # @param [String] content the initial content to set
  # @option _rte [Array<Selection>] selections array containing all the current selections
  # @option _rte [Array<String>] words array containing all the words of the text
  #
  constructor: (content = '')->
    if content.constructor is String
      @_rte = {}
      @_rte.styles = []
      @_rte.selections = []
      @_rte.cursorInformation = {}
      @_rte.words = []
      @push(content)
    else
      return

    nSelec = new Selection start, end, s.style
    rte.getWord()


# Class describing the Rich Text Editor type
#

  #
  # @param [Selection] sel the selection to delete
  #
  deleteSel: (selection) ->
    if not selection.isValid()
      throw new Error "Invalid selection"
    if not 0 <= selection.startPos.loc <= @getWord(selection.startPos.word).length
      throw new Error "Invalid selection"
    if not 0 <= selection.endPos.loc <= @getWord(selection.endPos.word).length
      throw new Error "Invalid selection"

    start = selection.startPos.word
    end = selection.endPos.word

    newLeft = @getWord(s).substring(0, selection.startPos.pos)
    newRight = @getWord(e).substring(selection.endPos.pos)

    if start == end
      @setWord(start, newLeft + newRight)

      # delete the words in between
      @deleteWords(start+1, end)
    else
      @setWord(start, newLeft)
      @setWord(end, newRight)

      # delete the words in between
      @deleteWords(start+1, end)
      # merge
      @merge(start)

  # Insert text at position
  #
  # @param [Option] position The position where to insert text
  # @param [String] content the content to insert
  #
  insert: (selection, content)->
    if (_.isUndefined selection.startPos)
      throw new Error "Expected a location object as first argument"
    if not (_.isString content)
      throw new Error "Expected a string as second argument"

    if content.length == 0
      return
    index = selection.startPos.word   #position to work from
    pos = selection.startPos.pos

    preSpaces = content.match PreSpacesRegExp
    currWord = @getWord index
