   # Convert indexes from beginning of text to coordinates expressed in word and
   # position within word
   #
-  # @param [Integer] untilStart index from first character
-  # @param [Integer] untilEnd index from first character
+  # @param [Integer] position index of position to find
   # @param [Rte] rte a rich text editor instance
-  _relativeFromAbsolute: (untilStart, untilEnd, rte)->
-    # Convert absolute coordinates to relatives
-    spw = spp = epw = epp = 0
-
-    words = rte._rte.words
-    for i in [0..words.length-1]
-      l = rte.getWord(i).length
-      if l >= untilStart
-        spp = untilStart
-        untilStart = 0
+  _relativeFromAbsolute: (position, rte)->
+    index = 0
+
+    while position > 0
+      if index >= rte._rte.words.length
+        return {word: index, pos: 0}
+      if rte._rte.words[index].word.length > position
+        return {word: index, pos: position}
       else
-        spw += 1
-        untilStart -= l
-
-      if l >= untilEnd
-        # throw new Error(untilEnd)
-        epp = untilEnd
-        untilEnd = 0
-      else
-        epw += 1
-        untilEnd -= l
-      if untilStart == untilEnd == 0
-        break
-
-    [{word: spw, pos: spp}, {word: epw, pos: epp}]
+        position -= rte._rte.words[index].word.length
+        index += 1
+    return {word: index, pos: position}
 
   # Compares the bounds of two selections
   #

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

    preSpaces = content.search PreSpacesRegExp

    currWord = @getWord index

    # move the spaces to the previous word if a pos == 0
    if preSpaces > -1
      if pos == 0
        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

        throw new Error "Expecting numbers as arguments"
      c.constructor is "Rte"

      @startPos = @_relativeFromAbsolute a, c
      @endPos = @_relativeFromAbsolute b, c
      style = d

    else if not _.isUndefined(a) and not _.isUndefined(b) and
      a.pos? and a.word? and
       b.pos? and b.word?
      @startPos = a
      @endPos = b

