From 9f19676dc21477d2447ce2734613d35b713b3ff8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 30 Mar 2022 15:49:38 +0200 Subject: [PATCH] :bug: Fix problem with wheel-zoom on an editing text --- frontend/src/app/main/ui/workspace/viewport.cljs | 5 +++-- .../src/app/main/ui/workspace/viewport/actions.cljs | 12 +++++++----- .../src/app/main/ui/workspace/viewport/hooks.cljs | 4 ++-- frontend/src/app/util/dom.cljs | 5 +++++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 2eba7eeca..900dd304b 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -88,6 +88,7 @@ ;; REFS viewport-ref (mf/use-ref nil) + overlays-ref (mf/use-ref nil) ;; VARS disable-paste (mf/use-var false) @@ -169,7 +170,7 @@ disabled-guides? (or drawing-tool transform)] - (hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?) + (hooks/setup-dom-events viewport-ref overlays-ref zoom disable-paste in-viewport?) (hooks/setup-viewport-size viewport-ref) (hooks/setup-cursor cursor alt? mod? space? panning drawing-tool drawing-path? node-editing?) (hooks/setup-keyboard alt? mod? space?) @@ -179,7 +180,7 @@ (hooks/setup-active-frames base-objects vbox hover active-frames) [:div.viewport - [:div.viewport-overlays + [:div.viewport-overlays {:ref overlays-ref} [:& wtr/frame-renderer {:objects base-objects :background background}] diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 0ad3de7a0..111a0fa91 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -363,21 +363,23 @@ pt (utils/translate-point-to-viewport viewport zoom raw-pt)] (rx/push! move-stream pt))))) -(defn on-mouse-wheel [viewport-ref zoom] +(defn on-mouse-wheel [viewport-ref overlays-ref zoom] (mf/use-callback (mf/deps zoom) (fn [event] (let [viewport (mf/ref-val viewport-ref) + overlays (mf/ref-val overlays-ref) event (.getBrowserEvent ^js event) - target (dom/get-target event)] - (when (.contains ^js viewport target) + target (dom/get-target event) + mod? (kbd/mod? event)] + + (when (or (dom/is-child? viewport target) + (dom/is-child? overlays target)) (dom/prevent-default event) (dom/stop-propagation event) (let [pt (->> (dom/get-client-position event) (utils/translate-point-to-viewport viewport zoom)) - mod? (kbd/mod? event) - delta-mode (.-deltaMode ^js event) unit (cond diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index 11e4bc006..d2e70e878 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -27,11 +27,11 @@ [rumext.alpha :as mf]) (:import goog.events.EventType)) -(defn setup-dom-events [viewport-ref zoom disable-paste in-viewport?] +(defn setup-dom-events [viewport-ref overlays-ref zoom disable-paste in-viewport?] (let [on-key-down (actions/on-key-down) on-key-up (actions/on-key-up) on-mouse-move (actions/on-mouse-move viewport-ref zoom) - on-mouse-wheel (actions/on-mouse-wheel viewport-ref zoom) + on-mouse-wheel (actions/on-mouse-wheel viewport-ref overlays-ref zoom) on-paste (actions/on-paste disable-paste in-viewport?)] (mf/use-layout-effect (mf/deps on-key-down on-key-up on-mouse-move on-mouse-wheel on-paste) diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index 0aba75592..64ba990dc 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -530,3 +530,8 @@ (when onfinish (set! (.-onfinish animation) onfinish))))) +(defn is-child? + [^js node ^js candidate] + (and (some? node) + (some? candidate) + (.contains node candidate)))