   # @param [Selection] selection the selection to compare to this
   #
   in: (selection) ->
-    @startPos.gt(selection.startPos) and @endPos.lt(selection.endPos)
+    @gt(selection.left, selection.leftPos, "left") and
+    @lt(selection.right, selection.rightPos, "right")
 
   # Returns true if the current selection is in the given selection
   #

    if @ == selection
      return
    if @style != selection.style
      return false
    if @atLeftOf selection
      leftSel = @
      rightSel = selection

_ = require 'underscore'

# Function that translates an index from start (absolute position) into a
# relative position in word index and offset
#
# @param [Integer] position the position
# @param [Rte] rte an rte instance
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
        position -= rte._rte.words[index].word.length
        index += 1
    return {word: index, pos: position}

# Function that translates an index from start (absolute position) into a
# relative position in word index and offset
#
# @param [Option] relative the position
# @param [Rte] rte an rte instance
absoluteFromRelative = (index, offset, rte) ->
  absolute = offset
  if index > 0
    for i in [0..(index-1)]
      absolute += rte.getWord(i).word.length

  absolute

# XRegExp = require('xregexp').XRegExp
WordRegExp = /\S+\s*/g
