Browse code

Autocomplete when submitting, if a suggestion is selected

Fixes #60.

Joseph Weston authored on 22/10/2022 03:34:22
Showing 1 changed files
... ...
@@ -84,10 +84,16 @@
84 84
      (assoc-in [:cmdline :suggestions] {:options nil :selected nil}))))
85 85
 
86 86
 
87
+(defn with-autocomplete [{:keys [current suggestions]}]
88
+  (if (some-> suggestions :selected)
89
+      (nth (suggestions :options) (suggestions :selected))
90
+      current))
91
+
92
+
87 93
 (re-frame/reg-event-fx
88 94
  ::submit-cmdline
89 95
  (fn [cofx _]
90
-   {:fx [[:dispatch [::execute (-> cofx :db :cmdline :current)]]
96
+   {:fx [[:dispatch [::execute (-> cofx :db :cmdline with-autocomplete)]]
91 97
          [:dispatch [::clear-cmdline]]]}))
92 98
 
93 99