Skip to content

Commit

Permalink
enhance(editor): optimize global keystrokes effect
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 authored and tiensonqin committed Nov 4, 2021
1 parent 179a8de commit 52c65e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/main/frontend/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
(ui/inject-document-devices-envs!)
(ui/inject-dynamic-style-node!)
(plugin-handler/host-mounted!)
(let [td-fns [(ui/setup-active-keystroke!)
(ui/setup-active-keystroke!)]
teardown-fn #(mapv (fn [f] (f)) td-fns)]
(let [teardown-fn (comp (ui/setup-active-keystroke!))]
(assoc state ::teardown teardown-fn)))
:will-unmount (fn [state]
(let [teardown (::teardown state)]
Expand Down
7 changes: 5 additions & 2 deletions src/main/frontend/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
["react-tippy" :as react-tippy]
["react-transition-group" :refer [CSSTransition TransitionGroup]]
["react-tweet-embed" :as react-tweet-embed]
[rum.core :as rum]))
[rum.core :as rum]
[clojure.string :as str]))

(defonce transition-group (r/adapt-class TransitionGroup))
(defonce css-transition (r/adapt-class CSSTransition))
Expand Down Expand Up @@ -303,11 +304,13 @@

(defn setup-active-keystroke! []
(let [active-keystroke (atom #{})
heads #{:shift :alt :meta :control}
handle-global-keystroke (fn [down? e]
(let [handler (if down? conj disj)
keystroke e.key]
(swap! active-keystroke handler keystroke))
(set-global-active-keystroke (apply str (interpose "+" (vec @active-keystroke)))))
(when (contains? heads (keyword (util/safe-lower-case e.key)))
(set-global-active-keystroke (str/join "+" @active-keystroke))))
keydown-handler (partial handle-global-keystroke true)
keyup-handler (partial handle-global-keystroke false)
clear-all #(do (set-global-active-keystroke "")
Expand Down

0 comments on commit 52c65e8

Please sign in to comment.