Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pdf): add zoom via touchpad #10435

Merged
merged 7 commits into from Oct 31, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/frontend/extensions/pdf/core.cljs
Expand Up @@ -464,6 +464,38 @@
(set-end! (calc-coords! (.-pageX e) (.-pageY e))))
[])]


(let [zoom-viewer!
(rum/use-callback
(util/debounce
10 (fn [delta]
(if (> delta 0)
((partial pdf-utils/zoom-out-viewer viewer))
((partial pdf-utils/zoom-in-viewer viewer)))
)
)
[viewer])]

;; zoom using touchpad
(rum/use-effect!
(fn []
(when-let [^js/HTMLElement root cnt-el]
(let [fn-wheel (fn [^js/WheelEvent e]
(let [delta (or (.-deltaY e) (.-detail e) (.-wheelDelta e))]
;; to exclude horizontal scrolling
(when (not (integer? delta))
(p/do! (zoom-viewer! delta))
))
)]
(doto root
(.addEventListener "wheel" fn-wheel))

;; destroy
#(doto root
(.removeEventListener "wheel" fn-wheel)))))
[zoom-viewer!])
)

(rum/use-effect!
(fn []
(when-let [^js/HTMLElement root cnt-el]
Expand Down