                  (indent-mode old-text old-x old-line))
         new-text (:text result)
         new-x (:x result)
-        new-pos (+ old-pos (- new-x old-x))]
+        new-pos (row-col->index new-text old-line new-x)]
     (.setText text-area new-text)
     (.setCaretPosition text-area new-pos)))
 
 (defn init-parinfer!
-  [text-area extension]
+  [^TextEditorPane text-area extension]
   (when (contains? utils/clojure-exts extension)
     ; use paren mode to preprocess the code
     (let [old-text (.getText text-area)]

(ns nightcode.editors
  (:require [clojure.java.io :as io]
            [flatland.ordered.map :as flatland]
            [nightcode.completions :as completions]
            [nightcode.dialogs :as dialogs]

    {:x (.-cursorX res) :text (.-text res)}))

(defn indent-mode [text x line]
  (let [^ParinferResult res (Parinfer/indentMode text (int x) (int line) nil)]
    {:x (.-cursorX res) :text (.-text res)}))

(defn row-col->index
  [text row col]
  (let [s (join \newline (take row (split text #"\n")))
        index (+ (count s) (inc col))]
    index))

(defn run-parinfer!
  [^TextEditorPane text-area paren-mode?]
  (let [old-pos (.getCaretPosition text-area)
        old-x (.getCaretOffsetFromLineStart text-area)
        old-line (.getCaretLineNumber text-area)
