Przeglądaj źródła

enhance: fuzzy search commands

Tienson Qin 2 lat temu
rodzic
commit
81215e0b1f
1 zmienionych plików z 11 dodań i 10 usunięć
  1. 11 10
      src/main/frontend/components/cmdk.cljs

+ 11 - 10
src/main/frontend/components/cmdk.cljs

@@ -154,16 +154,17 @@
     (swap! !results assoc-in [group :status] :loading)
     (if (empty? @!input)
       (swap! !results update group merge {:status :success :items default-commands})
-      (->> (cp-handler/top-commands 1000)
-           (map #(assoc % :t (cp/translate t %)))
-           (filter #(string/includes? (lower-case-str (pr-str %)) (lower-case-str @!input)))
-           (map #(hash-map :icon "command"
-                           :icon-theme :gray
-                           :text (cp/translate t %)
-                           :shortcut (:shortcut %)
-                           :source-command %))
-           (hash-map :status :success :items)
-           (swap! !results update group merge)))))
+      (let [commands (->> (cp-handler/top-commands 1000)
+                          (map #(assoc % :t (cp/translate t %))))
+            search-results (search/fuzzy-search commands @!input {:extract-fn :t})]
+        (->> search-results
+             (map #(hash-map :icon "command"
+                             :icon-theme :gray
+                             :text (cp/translate t %)
+                             :shortcut (:shortcut %)
+                             :source-command %))
+             (hash-map :status :success :items)
+             (swap! !results update group merge))))))
 
 ;; The pages search action uses an existing handler
 (defmethod load-results :pages [group state]