Преглед на файлове

fix: wheel zoom normalization (#5165)

Co-authored-by: David Luzar <luzar.david@gmail.com>
Johannes преди 3 години
родител
ревизия
33bb23d2f3
променени са 1 файла, в които са добавени 9 реда и са изтрити 8 реда
  1. 9 8
      src/components/App.tsx

+ 9 - 8
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<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(