Skip to content

Commit

Permalink
enhance(shortcut): support intuitional keyboard chars for binding key
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 authored and tiensonqin committed May 6, 2022
1 parent e8e6e48 commit 7a7dbd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions libs/src/LSPlugin.ts
Expand Up @@ -308,6 +308,12 @@ export interface IAppProxy {
action: SimpleCommandCallback
) => void

/**
* Supported key names
* @link https://gist.github.com/xyhp915/d1a6d151a99f31647a95e59cdfbf4ddc
* @param keybinding
* @param action
*/
registerCommandShortcut: (
keybinding: SimpleCommandKeybinding,
action: SimpleCommandCallback
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/modules/shortcut/core.cljs
Expand Up @@ -66,7 +66,7 @@
(doseq [k (dh/shortcut-binding id)]
(try
(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
(log/error :shortcut/register-shortcut {:id id
:binding k
Expand All @@ -81,7 +81,7 @@
(when-let [handler (get-handler-by-id handler-id)]
(when-let [ks (dh/shortcut-binding shortcut-id)]
(doseq [k ks]
(.unregisterShortcut ^js handler k)))
(.unregisterShortcut ^js handler (dh/normalize-user-keyname k))))
(shortcut-config/remove-shortcut! handler-id shortcut-id)))

(defn uninstall-shortcut!
Expand Down
11 changes: 11 additions & 0 deletions src/main/frontend/modules/shortcut/data_helper.cljs
Expand Up @@ -44,6 +44,17 @@
shortcut)
(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
(defn binding-by-category [name]
(let [dict (->> (vals @config/config)
Expand Down

0 comments on commit 7a7dbd5

Please sign in to comment.