diff --git a/frontend/src/uxbox/main/ui/shapes/common.cljs b/frontend/src/uxbox/main/ui/shapes/common.cljs index d3f21b17d..3600e803c 100644 --- a/frontend/src/uxbox/main/ui/shapes/common.cljs +++ b/frontend/src/uxbox/main/ui/shapes/common.cljs @@ -32,16 +32,13 @@ (ptk/reify ::start-move-selected ptk/WatchEvent (watch [_ state stream] - (let [flags (get-in state [:workspace-local :flags]) - selected (get-in state [:workspace-local :selected]) + (let [selected (get-in state [:workspace-local :selected]) stoper (rx/filter uws/mouse-up? stream) zero-point? #(= % (gpt/point 0 0)) - position @uws/mouse-position - deltas (atom 0)] + position @uws/mouse-position] (rx/concat (->> (uws/mouse-position-deltas position) (rx/filter (complement zero-point?)) - (rx/tap #(swap! deltas inc)) (rx/map #(dw/apply-displacement-in-bulk selected %)) (rx/take-until stoper)) (rx/of (dw/materialize-displacement-in-bulk selected))))))) @@ -50,8 +47,7 @@ (ptk/reify ::start-move-frame ptk/WatchEvent (watch [_ state stream] - (let [flags (get-in state [:workspace-local :flags]) - selected (get-in state [:workspace-local :selected]) + (let [selected (get-in state [:workspace-local :selected]) stoper (rx/filter uws/mouse-up? stream) zero-point? #(= % (gpt/point 0 0)) frame-id (first selected) diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 6ef975bbb..04d676ae5 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -14,6 +14,7 @@ [potok.core :as ptk] [rumext.alpha :as mf] [uxbox.builtins.icons :as i] + [uxbox.common.data :as d] [uxbox.main.constants :as c] [uxbox.main.data.workspace :as dw] [uxbox.main.geom :as geom] @@ -222,14 +223,19 @@ (st/emit! ::finish-positioning #_(dw/stop-viewport-positioning))) (st/emit! (ms/->KeyboardEvent :up key ctrl? shift?)))) + translate-point-to-viewport + (fn [pt] + (let [viewport (mf/ref-node viewport-ref) + brect (.getBoundingClientRect viewport) + brect (gpt/point (d/parse-integer (.-left brect)) + (d/parse-integer (.-top brect)))] + (gpt/subtract pt brect))) + on-mouse-move (fn [event] - ;; NOTE: offsetX and offsetY are marked as "experimental" on - ;; MDN site but seems like they are supported on all - ;; browsers so we can avoid translation opetation just using - ;; this attributes. - (let [pt (dom/get-offset-position event)] - (reset! last-position pt) + (let [pt (gpt/point (.-clientX event) + (.-clientY event)) + pt (translate-point-to-viewport pt)] (st/emit! (ms/->PointerEvent :viewport pt (kbd/ctrl? event) (kbd/shift? event)))))