 ;; Creating
 ;;*********************************************************
 
-(def ed-id (atom 0))
-
-(defn ed-with-elem [$elem opts]
-  (js/CodeMirror (if (.-get $elem)
-                   (.get $elem 0)
-                   $elem)
-                 (clj->js opts)))
-
-(defn ed-headless [opts]
+(defn headless [opts]
   (-> (js/CodeMirror. (fn []))
       (set-options opts)))
 
-(defn ->editor [opts]
-  (let [ed (ed-headless opts)]
-    (set! (.-ltid ed) (swap! ed-id inc))
-    (set! (.-ltproperties ed) (atom {}))
-    ed))
-
-(defn init [ed context]
-  (-> ed
-      (clear-props)
-      (set-props (dissoc context :content :doc))
-      (set-val (:content context))
-      (set-options {:mode (name (:mime context))
-                    :readOnly false
-                    :dragDrop false
-                    :lineNumbers false
-                    :lineWrapping true})))
-
 (defn make [context]
-  (let [e (->editor {:mode (if (:mime context)
+  (let [e (headless {:mode (if (:mime context)
                              (name (:mime context))
                              "plaintext")
                      :autoClearEmptyLines true

                     :onDragEvent (fn [] true)
                     :undoDepth 10000
                     :matchBrackets true})]
    (set-props e (dissoc context :content :doc))
    (when-let [c (:content context)]
      (set-val e c)
      (clear-history e))

                      (set-options obj {:tabSize tab-size
                                        :indentWithTabs use-tabs?
                                        :indentUnit indent-unit})))

(behavior ::set-codemirror-flags
          :triggers #{:object.instant}
          :type :user
          :desc "Editor: Set CodeMirror flags"
          :params [{:label "Flags map"
                    :ex "{:undoDepth 1000}"}]
          :reaction (fn [this flags]
                      (set-options this flags)))

(behavior ::read-only
          :triggers #{:object.instant}
