mirror of https://github.com/logseq/logseq
enhance(shortcut): support intuitional keyboard chars for binding key
parent
e8e6e48b77
commit
7a7dbd5e68
|
@ -308,6 +308,12 @@ export interface IAppProxy {
|
||||||
action: SimpleCommandCallback
|
action: SimpleCommandCallback
|
||||||
) => void
|
) => void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported key names
|
||||||
|
* @link https://gist.github.com/xyhp915/d1a6d151a99f31647a95e59cdfbf4ddc
|
||||||
|
* @param keybinding
|
||||||
|
* @param action
|
||||||
|
*/
|
||||||
registerCommandShortcut: (
|
registerCommandShortcut: (
|
||||||
keybinding: SimpleCommandKeybinding,
|
keybinding: SimpleCommandKeybinding,
|
||||||
action: SimpleCommandCallback
|
action: SimpleCommandCallback
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
(doseq [k (dh/shortcut-binding id)]
|
(doseq [k (dh/shortcut-binding id)]
|
||||||
(try
|
(try
|
||||||
(log/debug :shortcut/register-shortcut {:id id :binding k})
|
(log/debug :shortcut/register-shortcut {:id id :binding k})
|
||||||
(.registerShortcut handler (util/keyname id) k)
|
(.registerShortcut handler (util/keyname id) (dh/normalize-user-keyname k))
|
||||||
(catch js/Object e
|
(catch js/Object e
|
||||||
(log/error :shortcut/register-shortcut {:id id
|
(log/error :shortcut/register-shortcut {:id id
|
||||||
:binding k
|
:binding k
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
(when-let [handler (get-handler-by-id handler-id)]
|
(when-let [handler (get-handler-by-id handler-id)]
|
||||||
(when-let [ks (dh/shortcut-binding shortcut-id)]
|
(when-let [ks (dh/shortcut-binding shortcut-id)]
|
||||||
(doseq [k ks]
|
(doseq [k ks]
|
||||||
(.unregisterShortcut ^js handler k)))
|
(.unregisterShortcut ^js handler (dh/normalize-user-keyname k))))
|
||||||
(shortcut-config/remove-shortcut! handler-id shortcut-id)))
|
(shortcut-config/remove-shortcut! handler-id shortcut-id)))
|
||||||
|
|
||||||
(defn uninstall-shortcut!
|
(defn uninstall-shortcut!
|
||||||
|
|
|
@ -44,6 +44,17 @@
|
||||||
shortcut)
|
shortcut)
|
||||||
(mapv mod-key)))))
|
(mapv mod-key)))))
|
||||||
|
|
||||||
|
(defn normalize-user-keyname
|
||||||
|
[k]
|
||||||
|
(some-> k
|
||||||
|
(util/safe-lower-case)
|
||||||
|
(str/replace #";+" "semicolon")
|
||||||
|
(str/replace #"=+" "equals")
|
||||||
|
(str/replace #"~+" "dash")
|
||||||
|
(str/replace "[" "open-square-bracket")
|
||||||
|
(str/replace "]" "close-square-bracket")
|
||||||
|
(str/replace "'" "single-quote")))
|
||||||
|
|
||||||
;; returns a vector to preserve order
|
;; returns a vector to preserve order
|
||||||
(defn binding-by-category [name]
|
(defn binding-by-category [name]
|
||||||
(let [dict (->> (vals @config/config)
|
(let [dict (->> (vals @config/config)
|
||||||
|
|
Loading…
Reference in New Issue