Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feature: CTRL + "+" to zoom into canvas instead of browser… #3848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion frontend/src/app/main/streams.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

;; --- User Events

(defrecord KeyboardEvent [type key shift ctrl alt meta editing])
(defrecord KeyboardEvent [type key shift ctrl alt meta editing event])

(defn keyboard-event?
[v]
Expand Down Expand Up @@ -184,6 +184,28 @@
keyboard-meta
keyboard-ctrl))

(defonce keyboard-minus-or-underscore
(let [sub (rx/behavior-subject nil)
ob (->> st/stream
(rx/filter keyboard-event?)
(rx/filter key-down?)
(rx/filter #(kbd/mod? (:event %)))
(rx/filter #(or (kbd/minus? %) (kbd/underscore? %)))
(rx/dedupe))]
(rx/subscribe-with ob sub)
sub))

(defonce keyboard-=-or-+
(let [sub (rx/behavior-subject nil)
ob (->> st/stream
(rx/filter keyboard-event?)
(rx/filter key-down?)
(rx/filter #(kbd/mod? (:event %)))
(rx/filter #(or (kbd/equals? %) (kbd/plus? %)))
(rx/dedupe))]
(rx/subscribe-with ob sub)
sub))

(defonce keyboard-space
(let [sub (rx/behavior-subject nil)
ob (->> st/stream
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/main/ui/workspace/viewport/actions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
(= "TEXTAREA" (obj/get target "tagName")))]

(when-not (.-repeat bevent)
(st/emit! (ms/->KeyboardEvent :down key shift? ctrl? alt? meta? editing?)))))))
(st/emit! (ms/->KeyboardEvent :down key shift? ctrl? alt? meta? editing? event)))))))

(defn on-key-up []
(mf/use-callback
Expand All @@ -336,7 +336,7 @@
(= "rich-text" (obj/get target "className"))
(= "INPUT" (obj/get target "tagName"))
(= "TEXTAREA" (obj/get target "tagName")))]
(st/emit! (ms/->KeyboardEvent :up key shift? ctrl? alt? meta? editing?))))))
(st/emit! (ms/->KeyboardEvent :up key shift? ctrl? alt? meta? editing? event))))))

(defn on-pointer-move [move-stream]
(let [last-position (mf/use-var nil)]
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/main/ui/workspace/viewport/hooks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
(reset! mod? %)
(when-not % (reset! z? false)))) ;; In mac after command+z there is no event for the release of the z key
(hooks/use-stream ms/keyboard-space #(reset! space? %))
(hooks/use-stream ms/keyboard-=-or-+ #(do
(dom/prevent-default (:event %))
(st/emit! (dw/increase-zoom))))
(hooks/use-stream ms/keyboard-minus-or-underscore #(do
(dom/prevent-default (:event %))
(st/emit! (dw/decrease-zoom))))
(hooks/use-stream ms/keyboard-z #(reset! z? %))
(hooks/use-stream ms/keyboard-shift #(reset! shift? %)))

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/util/keyboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
(def enter? (is-key? "Enter"))
(def space? (is-key? " "))
(def z? (is-key-ignore-case? "z"))
(def equals? (is-key? "="))
(def plus? (is-key? "+"))
(def minus? (is-key? "-"))
(def underscore? (is-key? "_"))
(def up-arrow? (is-key? "ArrowUp"))
(def down-arrow? (is-key? "ArrowDown"))
(def left-arrow? (is-key? "ArrowLeft"))
Expand Down