 {rangeIsCollapsed, rangesAreEqual, objectsAreEqual} = Trix
 
 class Trix.EditorController extends Trix.Controller
-  constructor: ({@editorElement, document}) ->
+  constructor: ({@editorElement, document, html}) ->
     document ?= new Trix.Document
 
     @selectionManager = new Trix.SelectionManager @editorElement


    @attachmentManager = new Trix.AttachmentManager @composition.getAttachments()
    @attachmentManager.delegate = this

    @undoManager = new Trix.UndoManager @composition

    @inputController = new Trix.InputController @editorElement
    @inputController.delegate = this

    @toolbarController = new Trix.ToolbarController @editorElement.toolbarElement
    @toolbarController.delegate = this

    if document?
      @loadDocument(document)
    else
      @loadHTML(html)

  loadHTML: (html = "") ->
    @loadDocument(Trix.Document.fromHTML(html))

  loadDocument: (document) ->
    @loadSnapshot({document, selectedRange: [0, 0]})

  loadSnapshot: (snapshot) ->
    @undoManager = new Trix.UndoManager @composition
    @composition.restoreSnapshot(snapshot)

  registerSelectionManager: ->
    Trix.selectionChangeObserver.registerSelectionManager(@selectionManager)
