       ""
       current-word-item)))
 
-(defn completions
-  "Autocomplete options for word"
-  [input dictionary options]
-  (let [last-string (last (string/split input #" "))
-        trim-chars (:trim-chars options)
-        sort-fn (:sort-fn options)
-        case-sensitive? (:case-sensitive? options)
-        complete-items (items-to-complete case-sensitive? dictionary last-string)]
-    (vec
-     (if trim-chars
-       (if (= (first last-string) (re-find (utils/str-to-pattern trim-chars) (str (first last-string))))
-         (->> 1
-              (subs last-string)
-              (items-to-complete case-sensitive? dictionary)
-              (sort-by sort-fn))
-         (sort-by sort-fn complete-items))
-       (sort-fn complete-items)))))
+(defn opening-excluded-chars [word excluded-chars]
+  (if ((set (map #(= (first word) %) excluded-chars)) true)
+    (opening-excluded-chars (apply str (rest word)) excluded-chars)
+    word))
+
+(defn closing-excluded-chars [word excluded-chars]
+  (if ((set (map #(= (last word) %) excluded-chars)) true)
+    (closing-excluded-chars (apply str (butlast word)) excluded-chars)
+    word))
+
+(defn completions [word dictionary {:keys [trim-chars sort-fn case-sensitive?]}]
+  (let [new-text (-> word
+                     (opening-excluded-chars trim-chars)
+                     (closing-excluded-chars trim-chars))]
+    (sort-by sort-fn (items-to-complete case-sensitive? dictionary new-text))))
 
 (defn words-to-index
   "Words to change index"



(defn case-sensitivity [case-sensitive? dictionary-item input]
  (if case-sensitive?
    (string/starts-with? dictionary-item input)
    (string/starts-with? (string/lower-case dictionary-item) (string/lower-case input))))

(defn items-to-complete
  "List of the items to autocomplete by given input and list of the all items"

  [index trim-chars text word-to-complete]
  (->> (update-in (string/split text #" ") [(index-of-word index text)]
                  #(complete-word-with-trimmed-chars (index-in-word index text)
                                                     %
                                                     word-to-complete
                                                     trim-chars))
       (string/join " ")))
