     (println "Editing: " pos key value)
     (save item pos)))
 
-(defn close
+(defn toggle-item-detail
+  [pos]
+  (let [opened (querydb [:opened])]
+    (if (contains? opened pos)
+      (updatedb [:opened] (disj opened pos))
+      (updatedb [:opened] (conj opened pos)))))
+
+(defn close-editor
   [pos]
   (let [editing (querydb [:editing])]
-    (updatedb [:editing] (disj editing pos))))
-
-;; Utils
-
-(defn blob?
-  [item]
-  (if (= (get item "type") "blob") true false))
-
-(defn editing?
-  [pos]
-  (contains? (querydb [:editing]) pos))
+    (updatedb [:editing] (disj editing pos))
+    (if (opened? pos) (toggle-item-detail pos))))
 
 ;; App
 


(defn querydb [fields]
  (get-in db fields))

(defn edit [pos]
  (let [editing (querydb [:editing])]

        level (count parts)
        base (last parts)
        icon (if (blob? item) (ftype-to-icon base) (nm "i.ftype.fa.fa-folder-open-o"))]
    (nm "div.pure-g" [(nm "div.pure-u-1.pure-u-sm-1-2"
                          [(nm (str "div.level" level) {:onclick #(toggle-item-detail index)} [icon base])])
                      (annotate index item)
                      (item-detail index item)])))

(defn reporender
  "Render repository trees"
