 (ns parinfer.editor
+  (:require-macros
+    [cljs.core.async.macros :refer [go go-loop]])
   (:require
+    [cljs.core.async :refer [<! timeout chan]]
     [clojure.string :as string :refer [join]]
     [parinfer.formatter :refer [format-text]]
     [cljsjs.codemirror]

      #(-> (or % empty-editor-state)
           (assoc :cm cm)))

    ;; Extend the code mirror object with some utility methods.
    (specify! cm
      IEditor
      (cm-key [this] key-)
      (frame-updated? [this] (get-in @frame-updates [key- :frame-updated?]))
      (set-frame-updated! [this value] (swap! frame-updates assoc-in [key- :frame-updated?] value)))

    ;; handle code mirror events
    (.on cm "change" on-change)

  "Called after the cursor moves in the editor."
  [cm]
  (when-not (frame-updated? cm)
    (record-change! cm {:selections (parse-selections (.listSelections cm))})
    (fix-text! cm))
  (set-frame-updated! cm false))

