From 33bb23d2f3f6d37686a6d2b88787d362164e46be Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 11 May 2022 21:01:20 +0100 Subject: [PATCH] fix: wheel zoom normalization (#5165) Co-authored-by: David Luzar --- src/components/App.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index b95d0c8f..66880b64 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -71,7 +71,6 @@ import { THEME, TOUCH_CTX_MENU_TIMEOUT, VERTICAL_ALIGN, - ZOOM_STEP, } from "../constants"; import { loadFromBlob } from "../data"; import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library"; @@ -5642,11 +5641,11 @@ class App extends React.Component { if (event.metaKey || event.ctrlKey) { const sign = Math.sign(deltaY); const MAX_STEP = 10; - let delta = Math.abs(deltaY); - if (delta > MAX_STEP) { - delta = MAX_STEP; + const absDelta = Math.abs(deltaY); + let delta = deltaY; + if (absDelta > MAX_STEP) { + delta = MAX_STEP * sign; } - delta *= sign; if (Object.keys(previousSelectedElementIds).length !== 0) { setTimeout(() => { this.setState({ @@ -5658,9 +5657,11 @@ class App extends React.Component { let newZoom = this.state.zoom.value - delta / 100; // increase zoom steps the more zoomed-in we are (applies to >100% only) - newZoom += Math.log10(Math.max(1, this.state.zoom.value)) * -sign; - // round to nearest step - newZoom = Math.round(newZoom * ZOOM_STEP * 100) / (ZOOM_STEP * 100); + newZoom += + Math.log10(Math.max(1, this.state.zoom.value)) * + -sign * + // reduced amplification for small deltas (small movements on a trackpad) + Math.min(1, absDelta / 20); this.setState((state) => ({ ...getStateForZoom(