         redo      ($ "button#redo")
         set-html! (fn [content] (. field (setHtml false content true)))]
     (do
+      (list-documents @docs)
       (if content (set-html! content))
       (. field (makeEditable))
       (. element (focus)))

       (goog.editor/Field. element)
       (goog.editor/SeamlessField. element))))

(defn launch [element doc-session]
  (let [field     (spawn-editor element)
        content   (doc-session :get :content)

                    CLICK
                    (fn [e] (dispatch/fire :document-requested (.-id item)))))))

(defn strip-html [s]
  (-> s
      (.replace "<br>" " ")
      (.replace "&nbsp;" " ")
      (.replace (js/RegExp. "(<([^>]+)>)" "ig") "")))

(defn excerpt [s chars]
  (.substring (strip-html s) 0 chars))

(defn list-documents [documents]
  (let [element ($ "#sidebar-documents > ol")
        sorted  (reverse (sort-by :ts documents))]
    (destroy-children! element)
    (doseq [[id doc] sorted]
      (append! element (single-node (str "<li id=\"" (name id) "\">"
                                           "<div class=\"excerpt\">"
                                             "<span>"
                                               (excerpt (:content doc) 20)
                                             "</span>"
                                           "</div>"
                                           "<div class=\"document-id\">"
                                             "<span>" (name id) "</span>"
                                           "</div>"
                                         "</li>"))))
    (add-documents-list-listeners)))

