        (fn [c]
          (let [config (r/props c)]
            (go (loop []
-                 (let [[text ch] (alts! [throttled-autocomplete-chan kill-chan])]
+                 (let [[data ch] (alts! [throttled-autocomplete-chan kill-chan])]
                    (when (= ch throttled-autocomplete-chan)
-                     (when-not (inside-code-block? text)
-                       (set-results!
-                         (seq (mapcat (fn [e] (e text)) @autocomplete-engines)))
-                       (highlight-first!))
+                     (let [{:keys [text pos]} data
+                           text (.slice text 0 pos)]
+                       (when-not (inside-code-block? text)
+                         (set-results!
+                           (seq (mapcat (fn [e] (e text)) @autocomplete-engines)))
+                         (highlight-first!)))
                      (recur)))))
            (go (loop []
                  (let [[v ch] (alts! [throttled-thread-text-chan

                         ;TODO


        handle-text-change! (fn [text]
                              (clear-force-close!)
                              (put! autocomplete-chan text))

        ; returns a function that can be used in a textarea's :on-key-down handler
        ; takes a callback fn, the textareas intended submit action

                      (update-thread-text! thread-id text)))

        update-text! (fn [f]
                       (let [{:keys [text pos]} @state
                             updated-text (f (.slice text 0 pos))
                             new-text (str updated-text (.slice text pos))]
                         (swap! state assoc :text new-text)
                         (update-thread-text! thread-id (@state :text))))

        choose-result!
        (fn [result]
