mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 19:36:37 +02:00
✨ Changed keyboard streams
This commit is contained in:
parent
d86dc608b0
commit
cd313dc2fe
3 changed files with 24 additions and 4 deletions
|
@ -11,7 +11,8 @@
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.util.globals :as globals]))
|
[app.util.globals :as globals])
|
||||||
|
(:import goog.events.KeyCodes))
|
||||||
|
|
||||||
;; --- User Events
|
;; --- User Events
|
||||||
|
|
||||||
|
@ -112,7 +113,9 @@
|
||||||
ob (->> (rx/merge
|
ob (->> (rx/merge
|
||||||
(->> st/stream
|
(->> st/stream
|
||||||
(rx/filter keyboard-event?)
|
(rx/filter keyboard-event?)
|
||||||
(rx/map :alt))
|
(rx/filter #(let [key (:key %)]
|
||||||
|
(= key KeyCodes.ALT)))
|
||||||
|
(rx/map #(= :down (:type %))))
|
||||||
;; Fix a situation caused by using `ctrl+alt` kind of shortcuts,
|
;; Fix a situation caused by using `ctrl+alt` kind of shortcuts,
|
||||||
;; that makes keyboard-alt stream registring the key pressed but
|
;; that makes keyboard-alt stream registring the key pressed but
|
||||||
;; on bluring the window (unfocus) the key down is never arrived.
|
;; on bluring the window (unfocus) the key down is never arrived.
|
||||||
|
@ -127,7 +130,11 @@
|
||||||
ob (->> (rx/merge
|
ob (->> (rx/merge
|
||||||
(->> st/stream
|
(->> st/stream
|
||||||
(rx/filter keyboard-event?)
|
(rx/filter keyboard-event?)
|
||||||
(rx/map :ctrl))
|
(rx/filter #(let [key (:key %)]
|
||||||
|
(or
|
||||||
|
(= key KeyCodes.CTRL)
|
||||||
|
(= key KeyCodes.META))))
|
||||||
|
(rx/map #(= :down (:type %))))
|
||||||
;; Fix a situation caused by using `ctrl+alt` kind of shortcuts,
|
;; Fix a situation caused by using `ctrl+alt` kind of shortcuts,
|
||||||
;; that makes keyboard-alt stream registring the key pressed but
|
;; that makes keyboard-alt stream registring the key pressed but
|
||||||
;; on bluring the window (unfocus) the key down is never arrived.
|
;; on bluring the window (unfocus) the key down is never arrived.
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
||||||
|
|
||||||
|
;; TODO: Move to another namespace
|
||||||
(ns app.main.ui.keyboard)
|
(ns app.main.ui.keyboard)
|
||||||
|
|
||||||
(defn is-keycode?
|
(defn is-keycode?
|
||||||
|
|
|
@ -57,7 +57,8 @@
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[rumext.alpha :as mf])
|
[rumext.alpha :as mf])
|
||||||
(:import goog.events.EventType
|
(:import goog.events.EventType
|
||||||
goog.events.WheelEvent))
|
goog.events.WheelEvent
|
||||||
|
goog.events.KeyCodes))
|
||||||
|
|
||||||
(defonce css-mouse?
|
(defonce css-mouse?
|
||||||
(cfg/check-browser? :firefox))
|
(cfg/check-browser? :firefox))
|
||||||
|
@ -465,6 +466,7 @@
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [bevent (.getBrowserEvent ^js event)
|
(let [bevent (.getBrowserEvent ^js event)
|
||||||
key (.-keyCode ^js event)
|
key (.-keyCode ^js event)
|
||||||
|
key (.normalizeKeyCode KeyCodes key)
|
||||||
ctrl? (kbd/ctrl? event)
|
ctrl? (kbd/ctrl? event)
|
||||||
shift? (kbd/shift? event)
|
shift? (kbd/shift? event)
|
||||||
alt? (kbd/alt? event)
|
alt? (kbd/alt? event)
|
||||||
|
@ -483,6 +485,7 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [key (.-keyCode event)
|
(let [key (.-keyCode event)
|
||||||
|
key (.normalizeKeyCode KeyCodes key)
|
||||||
ctrl? (kbd/ctrl? event)
|
ctrl? (kbd/ctrl? event)
|
||||||
shift? (kbd/shift? event)
|
shift? (kbd/shift? event)
|
||||||
alt? (kbd/alt? event)
|
alt? (kbd/alt? event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue