0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Merge pull request #5225 from penpot/azazeln28-panning-performance-improvement

 Improve panning code
This commit is contained in:
Andrey Antukh 2024-10-29 19:43:54 +01:00 committed by GitHub
commit acf273e4e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,6 @@
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.align :as gal]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as gpr]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
@ -150,19 +149,18 @@
ptk/WatchEvent
(watch [_ state stream]
(let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning)))
zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)]
zoom (get-in state [:workspace-local :zoom])]
(when-not (get-in state [:workspace-local :panning])
(rx/concat
(rx/of #(-> % (assoc-in [:workspace-local :panning] true)))
(->> stream
(rx/filter mse/pointer-event?)
(rx/filter #(= :delta (:source %)))
(rx/map :pt)
(rx/take-until stopper)
(rx/map (fn [delta]
(let [delta (gpt/divide delta zoom)]
(update-viewport-position {:x #(- % (:x delta))
:y #(- % (:y delta))})))))))))))
(rx/map (fn [event]
(let [delta (dm/get-prop event :pt)]
(update-viewport-position {:x #(- % (/ (:x delta) zoom))
:y #(- % (/ (:y delta) zoom))})))))))))))
(defn finish-panning []
(ptk/reify ::finish-panning