 
 setUpEditor = (id, html, onMutate) ->
   whenPresent (-> document.getElementById id),
-    ((elem) -> getEditorFor(elem, onMutate).writeHtml html),
+    ((elem) -> getEditorFor(elem, onMutate).writeHtml html, true),
     ((err) -> console.error "Could not write after 10,000 attempts:", id, html),
     10000
 

# Looks up the doc and snapshot associated with the given docId,
# writes the snapshot to the editor, and tells Elm about the new currentDocId
loadDocId = (docId) ->
  sync.getDoc(docId).then (doc) ->
    app.ports.loadAsCurrentDoc.send doc

    setUpEditor "edit-title", doc.title, (mutations, node) ->
      sync.getDoc(docId).then (doc) ->
        doc.title = node.textContent
        sync.saveDoc(doc).then -> app.ports.loadAsCurrentDoc.send doc

    setUpEditor "edit-description", doc.description, (mutations, node) ->
      sync.getDoc(docId).then (doc) ->
        doc.description = node.textContent
        sync.saveDoc(doc).then -> app.ports.loadAsCurrentDoc.send doc

    doc.chapters.forEach setUpChapter

setUpChapter = (chapter) ->
  chapterId = chapter.id

  setUpEditor "edit-chapter-heading-#{chapterId}", chapter.heading, (mutations, node) ->
    sync.getCurrentDocId().then (currentDocId) ->
      sync.getDoc(currentDocId).then (doc) ->
        for currentChapter in doc.chapters
          if currentChapter.id == chapterId
            currentChapter.heading = node.textContent

        sync.saveDoc(doc).then -> app.ports.loadAsCurrentDoc.send doc

