                       (+ len-last-line (.. change -from -ch)))]
           (- end-x start-x))))))
 
+(defn cm-process-text-change
+  [cm change prev-state]
+  (let [start-line (.. change -from -line)
+        end-line (inc (.. change -to -line))
+        num-new-lines (alength (.-text change))
+        lines (for [i (range start-line (+ start-line num-new-lines))]
+                (.getLine cm i))]
+    (infer/process-text-change
+      prev-state
+      {:line-no [start-line end-line]
+       :new-lines lines})))
  
 (defn fix-text!
   "Correctly format the text from the given editor."

(defprotocol IEditor
  "Custom data/methods for a CodeMirror editor."
  (cm-key [this])
  (frame-updated? [this])
  (set-frame-updated! [this value])
  (record-change! [this thing]))

           wrapper (.getWrapperElement cm)
           watcher (js/scrollMonitor.create wrapper)
           initial-state (assoc empty-editor-state
                                :mode (:parinfer-mode opts))
           prev-editor-state (atom nil)]


       (set! (.-id wrapper) (str "cm-" element-id))
