        (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

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

        update-text! (fn [f]
                       (swap! state update :text f)
                       (update-thread-text! thread-id (@state :text)))

        choose-result!
        (fn [result]

        autocomplete-on-change
        (fn [{:keys [on-change]}]
          (fn [e]
            (let [cursor-pos (.. e -target -selectionStart)]
              (handle-text-change! cursor-pos (.. e -target -value))
              (swap! state assoc :pos cursor-pos))
            (on-change e)))]

    (r/create-class
