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