 #= require trix/models/document
 #= require trix/models/line_break_insertion
 
-{normalizeRange, rangesAreEqual, objectsAreEqual, arrayStartsWith, summarizeArrayChange, getAllAttributeNames, getBlockConfig, getTextConfig, extend} = Trix
+{normalizeRange, rangesAreEqual, rangeIsCollapsed, objectsAreEqual, arrayStartsWith, summarizeArrayChange, getAllAttributeNames, getBlockConfig, getTextConfig, extend} = Trix
 
 class Trix.Composition extends Trix.BasicObject
   constructor: ->

    else
      @setDocument(@document.removeTextAtRange(range))
      @setSelection(range[0])
      false if block.isListItem()

  moveTextFromRange: (range) ->
    [position] = @getSelectedRange()

    @insertText(text)

  deleteInDirection: (direction) ->
    range = @getSelectedRange()
    selectionIsCollapsed = rangeIsCollapsed(range)
    block = @getBlock()

    if selectionIsCollapsed and direction is "backward"
      {offset} = @document.locationFromPosition(range[0])
      deletingIntoPreviousBlock = offset is 0

    if deletingIntoPreviousBlock
      if @canDecreaseBlockAttributeLevel()
        if block.isListItem()
          @decreaseListLevel()
        else
          @decreaseBlockAttributeLevel()

        @setSelection(range[0])
        return false if block.isEmpty()

    if selectionIsCollapsed
      range = @getExpandedRangeInDirection(direction)
      if direction is "backward"
        attachment = @getAttachmentAtRange(range)

