From 78a8d20e04fee17ad738179c12e4b5d6e3579650 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 26 Nov 2020 09:32:04 +0100 Subject: [PATCH] :sparkles: Prevent unexpected alt? state persistence on window blur. 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. --- frontend/src/app/main/streams.cljs | 19 +++++++++++++++---- .../src/app/main/ui/workspace/shapes.cljs | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/streams.cljs b/frontend/src/app/main/streams.cljs index 597f89223a..54b633d0e9 100644 --- a/frontend/src/app/main/streams.cljs +++ b/frontend/src/app/main/streams.cljs @@ -101,13 +101,24 @@ (rx/subscribe-with ob sub) sub)) + +(defonce window-blur + (->> (rx/from-event js/window "blur") + (rx/share))) + (defonce keyboard-alt (let [sub (rx/behavior-subject nil) - ob (->> st/stream - (rx/filter keyboard-event?) - (rx/map :alt) + ob (->> (rx/merge + (->> st/stream + (rx/filter keyboard-event?) + (rx/map :alt)) + ;; 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. + (->> window-blur + (rx/map (constantly false)))) (rx/dedupe))] - (rx/subscribe-with ob sub) + (rx/subscribe-with ob sub) sub)) (defn mouse-position-deltas diff --git a/frontend/src/app/main/ui/workspace/shapes.cljs b/frontend/src/app/main/ui/workspace/shapes.cljs index 2652591d4a..bb6e9603fb 100644 --- a/frontend/src/app/main/ui/workspace/shapes.cljs +++ b/frontend/src/app/main/ui/workspace/shapes.cljs @@ -86,7 +86,6 @@ (geom/translate-to-frame frame)) opts #js {:shape shape :frame frame} - alt? (mf/use-state false) on-mouse-enter (use-mouse-enter shape) on-mouse-leave (use-mouse-leave shape)