From 2a4849cf8f9c6ecef304ed7d64c5f639c66bc060 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 9 Mar 2021 14:49:28 +0100 Subject: [PATCH] :bug: Fix problem with middle mouse button press moving the canvas when not moving mouse --- CHANGES.md | 1 + frontend/src/app/main/streams.cljs | 25 ------------------- .../src/app/main/ui/workspace/viewport.cljs | 15 ++++++----- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3f2a62f31..268b5febb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ - Fix issue when undo after changing the artboard of a shape [Taiga #1304](https://tree.taiga.io/project/penpot/issue/1304) - Fix problem with system shortcuts and application [#737](https://github.com/penpot/penpot/issues/737) - Fix issue with typographies panel cannot be collapsed [#707](https://github.com/penpot/penpot/issues/707) +- Fix problem with middle mouse button press moving the canvas when not moving mouse [#717](https://github.com/penpot/penpot/issues/717) ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/streams.cljs b/frontend/src/app/main/streams.cljs index 969bae465..223462ded 100644 --- a/frontend/src/app/main/streams.cljs +++ b/frontend/src/app/main/streams.cljs @@ -143,28 +143,3 @@ (rx/dedupe))] (rx/subscribe-with ob sub) sub)) - -(defn mouse-position-deltas - [current] - (->> (rx/concat (rx/of current) - (rx/sample 10 mouse-position)) - (rx/buffer 2 1) - (rx/map (fn [[old new]] - (gpt/subtract new old))))) - - -(defonce mouse-position-delta - (let [sub (rx/behavior-subject nil) - ob (->> st/stream - (rx/filter pointer-event?) - (rx/filter #(= :delta (:source %))) - (rx/map :pt))] - (rx/subscribe-with ob sub) - sub)) - -(defonce viewport-scroll - (let [sub (rx/behavior-subject nil) - sob (->> (rx/filter scroll-event? st/stream) - (rx/map :point))] - (rx/subscribe-with sob sub) - sub)) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index a8c27ee33..24d48a6b7 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -131,18 +131,21 @@ (defn- handle-viewport-positioning [viewport-ref] (let [node (mf/ref-val viewport-ref) - stoper (rx/filter #(= ::finish-positioning %) st/stream) + stoper (rx/filter #(= ::finish-positioning %) st/stream)] - stream (->> ms/mouse-position-delta - (rx/take-until stoper))] (st/emit! dw/start-pan) - (rx/subscribe stream - (fn [delta] + + (->> st/stream + (rx/filter ms/pointer-event?) + (rx/filter #(= :delta (:source %))) + (rx/map :pt) + (rx/take-until stoper) + (rx/subs (fn [delta] (let [zoom (gpt/point @refs/selected-zoom) delta (gpt/divide delta zoom)] (st/emit! (dw/update-viewport-position {:x #(- % (:x delta)) - :y #(- % (:y delta))}))))))) + :y #(- % (:y delta))})))))))) ;; --- Viewport