 
 setUpChapter = (chapter) ->
   chapterId = chapter.id
-  headingEditorElemId = "edit-chapter-heading-#{chapterId}"
-  bodyEditorElemId    = "edit-chapter-body-#{chapterId}"
 
   # If you delete the chapter's body and heading, assume you want it gone.
   # (If you didn't, you can just re-add it; there couldn't have been data loss.)

loadAsCurrentDoc = (doc) ->
  app.ports.loadAsCurrentDoc.send doc

  setUpEditor "edit-title", doc.title, false, (mutations, node) ->
    sync.getDoc(doc.id).done (doc) ->
      doc.title = node.textContent
      sync.saveDoc(doc).done -> app.ports.setTitle.send doc.title

  setUpEditor "edit-description", doc.description, false, (mutations, node) ->
    sync.getDoc(doc.id).done (doc) ->
      doc.description = node.textContent
      sync.saveDoc(doc).done -> app.ports.setDescription.send doc.description

    editors.set elem, editor
    editor

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

