mirror of
https://github.com/penpot/penpot.git
synced 2025-07-31 21:38:30 +02:00
⚡ Optimize mousetrap binding setup
This commit is contained in:
parent
02cff2740f
commit
d84ee8bb65
1 changed files with 8 additions and 7 deletions
|
@ -142,23 +142,24 @@
|
||||||
[key cb]
|
[key cb]
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(log/debug :msg (str "Shortcut" key))
|
(log/debug :msg (str "Shortcut" key))
|
||||||
(when (aget event "preventDefault")
|
(when (unchecked-get event "preventDefault")
|
||||||
(.preventDefault event))
|
(.preventDefault event))
|
||||||
(cb event)))
|
(cb event)))
|
||||||
|
|
||||||
(defn- bind!
|
(defn- bind!
|
||||||
[shortcuts]
|
[shortcuts]
|
||||||
(let [msbind (fn [command callback type]
|
(let [msbind (fn [command callback type]
|
||||||
(if type
|
(let [command (if (vector? command)
|
||||||
(mousetrap/bind command callback type)
|
(into-array command)
|
||||||
(mousetrap/bind command callback)))]
|
command)]
|
||||||
|
(if type
|
||||||
|
(mousetrap/bind command callback type)
|
||||||
|
(mousetrap/bind command callback))))]
|
||||||
(->> shortcuts
|
(->> shortcuts
|
||||||
(remove #(:disabled (second %)))
|
(remove #(:disabled (second %)))
|
||||||
(run! (fn [[key {:keys [command fn type]}]]
|
(run! (fn [[key {:keys [command fn type]}]]
|
||||||
(let [callback (wrap-cb key fn)]
|
(let [callback (wrap-cb key fn)]
|
||||||
(if (vector? command)
|
(msbind command callback type)))))))
|
||||||
(run! #(msbind % callback type) command)
|
|
||||||
(msbind command callback type))))))))
|
|
||||||
|
|
||||||
(defn- reset!
|
(defn- reset!
|
||||||
([]
|
([]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue