     @toolbarController = new Trix.ToolbarController @editorElement.toolbarElement
     @toolbarController.delegate = this
 
-    @composition.setDocument(document)
-    @render()
+    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)


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

    @undoManager = new Trix.UndoManager @composition

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

{rangeIsCollapsed, rangesAreEqual, objectsAreEqual} = Trix

class Trix.EditorController extends Trix.Controller
  constructor: ({@editorElement, document, html}) ->
    document ?= new Trix.Document

    @selectionManager = new Trix.SelectionManager @editorElement
