mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
🐛 Fix problems with trackpad zoom and scroll in MacOS
This commit is contained in:
parent
1cac7d55d0
commit
0ed23f94c7
3 changed files with 23 additions and 27 deletions
|
@ -5,6 +5,7 @@
|
|||
### :bug: Bugs fixed
|
||||
|
||||
- Fix crash on iOS when displaying viewer [#1522](https://github.com/penpot/penpot/issues/1522)
|
||||
- Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161)
|
||||
|
||||
## 1.12.3-beta
|
||||
|
||||
|
|
|
@ -2102,4 +2102,3 @@
|
|||
(d/export dwgu/update-guides)
|
||||
(d/export dwgu/remove-guide)
|
||||
(d/export dwgu/set-hover-guide)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
(ns app.main.ui.workspace.viewport.actions
|
||||
(:require
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.math :as mth]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cfg]
|
||||
[app.main.data.workspace :as dw]
|
||||
|
@ -359,27 +360,19 @@
|
|||
(mf/use-callback
|
||||
(mf/deps zoom)
|
||||
(fn [event]
|
||||
(let [event (.getBrowserEvent ^js event)
|
||||
raw-pt (dom/get-client-position event)
|
||||
viewport (mf/ref-val viewport-ref)
|
||||
pt (utils/translate-point-to-viewport viewport zoom raw-pt)
|
||||
|
||||
ctrl? (kbd/ctrl? event)
|
||||
meta? (kbd/meta? event)
|
||||
(let [viewport (mf/ref-val viewport-ref)
|
||||
event (.getBrowserEvent ^js event)
|
||||
target (dom/get-target event)]
|
||||
(cond
|
||||
(or ctrl? meta?)
|
||||
(do
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(let [delta (+ (.-deltaY ^js event)
|
||||
(.-deltaX ^js event))]
|
||||
(if (pos? delta)
|
||||
(st/emit! (dw/decrease-zoom pt))
|
||||
(st/emit! (dw/increase-zoom pt)))))
|
||||
(when (.contains ^js viewport target)
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(let [pt (->> (dom/get-client-position event)
|
||||
(utils/translate-point-to-viewport viewport zoom))
|
||||
|
||||
(.contains ^js viewport target)
|
||||
(let [delta-mode (.-deltaMode ^js event)
|
||||
ctrl? (kbd/ctrl? event)
|
||||
meta? (kbd/meta? event)
|
||||
|
||||
delta-mode (.-deltaMode ^js event)
|
||||
|
||||
unit (cond
|
||||
(= delta-mode WheelEvent.DeltaMode.PIXEL) 1
|
||||
|
@ -393,13 +386,16 @@
|
|||
delta-x (-> (.-deltaX ^js event)
|
||||
(* unit)
|
||||
(/ zoom))]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(if (and (not (cfg/check-platform? :macos)) ;; macos sends delta-x automatically, don't need to do it
|
||||
(kbd/shift? event))
|
||||
(st/emit! (dw/update-viewport-position {:x #(+ % delta-y)}))
|
||||
(st/emit! (dw/update-viewport-position {:x #(+ % delta-x)
|
||||
:y #(+ % delta-y)})))))))))
|
||||
(if (or ctrl? meta?)
|
||||
(let [delta (* -1 (+ (.-deltaY ^js event) (.-deltaX ^js event)))
|
||||
scale (-> (+ 1 (/ delta 100)) (mth/clamp 0.77 1.3))]
|
||||
(st/emit! (dw/set-zoom pt scale)))
|
||||
(if (and (not (cfg/check-platform? :macos))
|
||||
;; macos sends delta-x automatically, don't need to do it
|
||||
(kbd/shift? event))
|
||||
(st/emit! (dw/update-viewport-position {:x #(+ % delta-y)}))
|
||||
(st/emit! (dw/update-viewport-position {:x #(+ % delta-x)
|
||||
:y #(+ % delta-y)}))))))))))
|
||||
|
||||
(defn on-drag-enter []
|
||||
(mf/use-callback
|
||||
|
|
Loading…
Add table
Reference in a new issue