   deleteSel: (selection) ->
     if not selection.isValid()
       throw new Error "Invalid selection"
-    if not 0 <= selection.startPos.loc <= @getWord(selection.startPos.word).word.length
-      throw new Error "Invalid selection"
-    if not 0 <= selection.endPos.loc <= @getWord(selection.endPos.word).word.length
-      throw new Error "Invalid selection"
-
-    start = selection.startPos.word
-    end = selection.endPos.word
-
-    newLeft = @getWord(start).word.substring(0, selection.startPos.pos)
-    newRight = @getWord(end).word.substring(selection.endPos.pos)
-
-    if start == end
-      @setWord(start, newLeft + newRight)
+
+    left = selection.left
+    right = selection.right
+
+    leftIndex = left.index @
+    rightIndex = right.index @
+
+    newLeft = left.word.substring(0, selection.leftPos)
+    newRight = right.word.substring(selection.rightPos)
+
+    if left == right
+      @setWord(leftIndex, newLeft + newRight)
 
       # delete the words in between
-      @deleteWords(start+1, end)
-    else
-      @setWord(start, newLeft)
-      @setWord(end, newRight)
+      @deleteWords(leftIndex+1, rightIndex)
+    else
+      @setWord(leftIndex, newLeft)
+      @setWord(rightIndex, newRight)
 
       # delete the words in between
-      @deleteWords(start+1, end)
+      @deleteWords(leftIndex+1, rightIndex)
       # merge
-      @merge(start)
+      @merge(leftIndex)
 
   # Insert text at position
   #

      if array[index].equals selection
        array.pop(index)
        break

# A class describing a selection with a style (bold, italic, …)
class Selection

  #
  # @param [Selection] selection the selection to compare to this
  atLeftOf: (selection) ->
    (@right == selection.left and
     @rightPos == selection.leftPos)

  #TODO
  setStyle: (@style) ->
