Optimize mousetrap binding setup

This commit is contained in:
Andrey Antukh 2025-07-29 12:48:56 +02:00
parent 02cff2740f
commit d84ee8bb65

View file

@ -142,23 +142,24 @@
[key cb]
(fn [event]
(log/debug :msg (str "Shortcut" key))
(when (aget event "preventDefault")
(when (unchecked-get event "preventDefault")
(.preventDefault event))
(cb event)))
(defn- bind!
[shortcuts]
(let [msbind (fn [command callback type]
(let [command (if (vector? command)
(into-array command)
command)]
(if type
(mousetrap/bind command callback type)
(mousetrap/bind command callback)))]
(mousetrap/bind command callback))))]
(->> shortcuts
(remove #(:disabled (second %)))
(run! (fn [[key {:keys [command fn type]}]]
(let [callback (wrap-cb key fn)]
(if (vector? command)
(run! #(msbind % callback type) command)
(msbind command callback type))))))))
(msbind command callback type)))))))
(defn- reset!
([]