From cd313dc2fef4062d6a8a6b838e34ff60ec111d0f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 15 Feb 2021 12:09:18 +0100 Subject: [PATCH] :sparkles: Changed keyboard streams --- frontend/src/app/main/streams.cljs | 13 ++++++++++--- frontend/src/app/main/ui/keyboard.cljs | 10 ++++++++++ frontend/src/app/main/ui/workspace/viewport.cljs | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/main/streams.cljs b/frontend/src/app/main/streams.cljs index 3529d2776..969bae465 100644 --- a/frontend/src/app/main/streams.cljs +++ b/frontend/src/app/main/streams.cljs @@ -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. diff --git a/frontend/src/app/main/ui/keyboard.cljs b/frontend/src/app/main/ui/keyboard.cljs index 93e49a6d5..95a59c4e5 100644 --- a/frontend/src/app/main/ui/keyboard.cljs +++ b/frontend/src/app/main/ui/keyboard.cljs @@ -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? diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index b5d79a0db..a495d37da 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -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)