Submit autocomplete suggestion on click.
Closes #12.
... | ... |
@@ -115,6 +115,19 @@ |
115 | 115 |
(let [{:keys [options selected]} suggestions] |
116 | 116 |
{:current (nth options selected) :suggestions null-suggestions})) |
117 | 117 |
|
118 |
+(re-frame/reg-event-db |
|
119 |
+ ::hover-suggestion |
|
120 |
+ (re-frame/path :cmdline) |
|
121 |
+ (fn [cmd [_ idx]] |
|
122 |
+ (assoc-in cmd [:suggestions :selected] idx))) |
|
123 |
+ |
|
124 |
+(re-frame/reg-event-fx |
|
125 |
+ ::click-suggestion |
|
126 |
+ (fn [cofx [_ prompt cmd]] |
|
127 |
+ (let [db (cofx :db)] |
|
128 |
+ {:db (assoc-in db [:cmdline :current] cmd) |
|
129 |
+ :fx [[:dispatch [::submit-cmd prompt]]]}))) |
|
130 |
+ |
|
118 | 131 |
(re-frame/reg-event-db |
119 | 132 |
::prompt-keypress |
120 | 133 |
(re-frame/path :cmdline) |
... | ... |
@@ -126,7 +139,6 @@ |
126 | 139 |
nil) |
127 | 140 |
tab (= (.-key event) "Tab") |
128 | 141 |
escape (= (.-key event) "Escape")] |
129 |
- (println (.-key event) direction (contains? #{:backward :forward} direction)) |
|
130 | 142 |
(cond |
131 | 143 |
(contains? #{:backward :forward} direction) (do (.preventDefault event) |
132 | 144 |
(if (some-> cmd :suggestions :options) |
... | ... |
@@ -213,6 +213,7 @@ |
213 | 213 |
:background-color (colorscheme :light0-soft)} |
214 | 214 |
[:li {:list-style :none |
215 | 215 |
:padding-left :3ch |
216 |
- :padding-right :1ch} |
|
216 |
+ :padding-right :1ch |
|
217 |
+ :cursor :pointer} |
|
217 | 218 |
[(s/& :.selected) |
218 | 219 |
{:background-color (colorscheme :neutral-purple)}]]]) |
... | ... |
@@ -60,7 +60,12 @@ |
60 | 60 |
(let [{:keys [options selected]} @suggestions] |
61 | 61 |
(for [[idx x] (enumerated options)] |
62 | 62 |
^{:key x} [:li |
63 |
- (when (= idx selected) {:class :selected}) |
|
63 |
+ {:class (when (= idx selected) :selected) |
|
64 |
+ :on-mouse-enter #(re-frame/dispatch [::events/hover-suggestion idx]) |
|
65 |
+ :on-click #(do (.preventDefault %) |
|
66 |
+ (re-frame/dispatch [::events/click-suggestion |
|
67 |
+ (-> % .-target .-parentElement .-parentElement) |
|
68 |
+ x]))} |
|
64 | 69 |
x]))]])) |
65 | 70 |
|
66 | 71 |
(defn title [] |