fix: wheel zoom normalization (#5165)

Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
Johannes 2022-05-11 21:01:20 +01:00 committed by GitHub
parent b27ac257e7
commit 33bb23d2f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<AppProps, AppState> {
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<AppProps, AppState> {
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(