     [position] = @getSelectedRange()
     @setDocument(@document.moveTextFromRangeToPosition(range, position))
     @setSelection(position)
+    @groupAdjacentAttachmentsAtPosition(position)
 
   removeAttachment: (attachment) ->
     if range = @document.getRangeOfAttachment(attachment)

      @insertAttachment(attachment)

  insertFiles: (files) ->
    headText = new Trix.Text
    tailText = new Trix.Text


      attachment.delegate = this
      @delegate?.compositionDidAddAttachment?(attachment)

  groupAdjacentAttachmentsAtPosition: (position) ->
    range = @document.getRangeOfPreviewableAttachmentsAtPosition(position)
    length = range[1] - range[0]
    if length > 1
