|
11 | 11 | [portal.ui.drag-and-drop :as dnd]
|
12 | 12 | [portal.ui.icons :as icons]
|
13 | 13 | [portal.ui.inspector :as ins]
|
| 14 | + [portal.ui.options :as options] |
14 | 15 | [portal.ui.state :as state]
|
15 | 16 | [portal.ui.styled :as s]
|
16 | 17 | [portal.ui.theme :as theme]
|
|
207 | 208 | [ins/inspector option]])))
|
208 | 209 | doall)]]]))))
|
209 | 210 |
|
210 |
| -(def default-map |
211 |
| - {#{"enter"} 'clojure.datafy/nav |
212 |
| - #{"shift" "enter"} 'clojure.datafy/datafy |
213 |
| - ["g" "d"] `portal.runtime.jvm.editor/goto-definition}) |
214 |
| - |
215 |
| -(def keymap (r/atom default-map)) |
| 211 | +(def ^:private client-keymap (r/atom {})) |
216 | 212 |
|
217 | 213 | (def ^:private aliases {"cljs.core" "clojure.core"})
|
218 | 214 |
|
|
221 | 217 | ns (str ns)]
|
222 | 218 | (symbol (aliases ns ns) (str name))))
|
223 | 219 |
|
224 |
| -(defn- find-combos [command] |
| 220 | +(defn- find-combos [keymap command] |
225 | 221 | (let [command-name (:name command)]
|
226 | 222 | (keep
|
227 |
| - #(into [] (sort %)) |
228 |
| - (keep |
229 |
| - (fn [[combo f]] |
230 |
| - (when (and (= f command-name) |
231 |
| - (shortcuts/platform-supported? combo)) |
232 |
| - combo)) |
233 |
| - @keymap)))) |
| 223 | + (fn [[combo f]] |
| 224 | + (when (and (= f command-name) |
| 225 | + (shortcuts/platform-supported? combo)) |
| 226 | + combo)) |
| 227 | + keymap))) |
234 | 228 |
|
235 | 229 | (def ^:private shortcut->symbol
|
236 | 230 | {"arrowright" [icons/arrow-right {:size "xs"}]
|
|
260 | 254 | :border-right [1 :solid (::c/border theme)]}}]])))]))
|
261 | 255 |
|
262 | 256 | (defn shortcut [command]
|
263 |
| - (let [theme (theme/use-theme)] |
| 257 | + (let [theme (theme/use-theme) |
| 258 | + opts (options/use-options)] |
264 | 259 | [s/div {:style
|
265 | 260 | {:display :flex
|
266 | 261 | :align-items :stretch
|
267 | 262 | :white-space :nowrap}}
|
268 | 263 | [separate
|
269 |
| - (for [combo (find-combos command)] |
| 264 | + (for [combo (concat (find-combos @client-keymap command) |
| 265 | + (find-combos (some-> opts :keymap deref) command))] |
270 | 266 | [:<>
|
271 | 267 | {:key (hash combo)}
|
272 | 268 | (map-indexed
|
|
903 | 899 | (let [m (meta var)
|
904 | 900 | name (or (:name opts) (var->name var))]
|
905 | 901 | (doseq [shortcut (concat (:shortcuts m) (:shortcuts opts))]
|
906 |
| - (swap! keymap assoc shortcut name)) |
| 902 | + (swap! client-keymap assoc shortcut name)) |
907 | 903 | (swap! registry
|
908 | 904 | assoc name (merge {:name name :run var}
|
909 | 905 | (when-let [doc (or (:doc m) (:doc opts))] {:doc doc})
|
|
1065 | 1061 |
|
1066 | 1062 | (defn palette [{:keys [container]}]
|
1067 | 1063 | (let [state (state/use-state)
|
1068 |
| - value (state/get-selected-value @state)] |
| 1064 | + value (state/get-selected-value @state) |
| 1065 | + opts (options/use-options)] |
1069 | 1066 | (react/useEffect
|
1070 | 1067 | (fn []
|
1071 | 1068 | (a/let [fns (state/invoke 'portal.runtime/get-functions value)]
|
|
1080 | 1077 | [with-shortcuts
|
1081 | 1078 | (fn [log]
|
1082 | 1079 | (when-not (shortcuts/input? log)
|
1083 |
| - (when-let [f (shortcuts/match @keymap log)] |
| 1080 | + (when-let [f (or (shortcuts/match @client-keymap log) |
| 1081 | + (shortcuts/match (some-> opts :keymap deref) log))] |
1084 | 1082 | (when-let [{:keys [run]} (or (get @registry f)
|
1085 | 1083 | (get @runtime-registry f))]
|
1086 |
| - |
1087 | 1084 | (shortcuts/matched! log)
|
1088 | 1085 | (run state)))))
|
1089 | 1086 | (when-let [component (::input @state)]
|
|
0 commit comments