           sync.saveSnapshot({id: chapter.snapshotId, html: node.innerHTML})
             .then (->) # TODO send a word count update
 
-
 saveHtmlAndLoadDoc = (html) ->
-  sync.saveFreshDoc(DocImport.docFromHtml html)
-    .then app.ports.loadAsCurrentDoc.send
+  sync.saveFreshDoc(DocImport.docFromHtml html).then loadAsCurrentDoc
 
 showFileChooser = ->
   new Promise (resolve, reject) ->

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

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



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

