0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

Changed keyboard streams

This commit is contained in:
alonso.torres 2021-02-15 12:09:18 +01:00 committed by Andrés Moya
parent d86dc608b0
commit cd313dc2fe
3 changed files with 24 additions and 4 deletions

View file

@ -11,7 +11,8 @@
[app.main.store :as st]
[app.main.refs :as refs]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]))
[app.util.globals :as globals])
(:import goog.events.KeyCodes))
;; --- User Events
@ -112,7 +113,9 @@
ob (->> (rx/merge
(->> st/stream
(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,
;; that makes keyboard-alt stream registring the key pressed but
;; on bluring the window (unfocus) the key down is never arrived.
@ -127,7 +130,11 @@
ob (->> (rx/merge
(->> st/stream
(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,
;; that makes keyboard-alt stream registring the key pressed but
;; on bluring the window (unfocus) the key down is never arrived.

View file

@ -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)
(defn is-keycode?

View file

@ -57,7 +57,8 @@
[promesa.core :as p]
[rumext.alpha :as mf])
(:import goog.events.EventType
goog.events.WheelEvent))
goog.events.WheelEvent
goog.events.KeyCodes))
(defonce css-mouse?
(cfg/check-browser? :firefox))
@ -465,6 +466,7 @@
(fn [event]
(let [bevent (.getBrowserEvent ^js event)
key (.-keyCode ^js event)
key (.normalizeKeyCode KeyCodes key)
ctrl? (kbd/ctrl? event)
shift? (kbd/shift? event)
alt? (kbd/alt? event)
@ -483,6 +485,7 @@
(mf/use-callback
(fn [event]
(let [key (.-keyCode event)
key (.normalizeKeyCode KeyCodes key)
ctrl? (kbd/ctrl? event)
shift? (kbd/shift? event)
alt? (kbd/alt? event)