Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix: wheel zoom normalization (#5165)

Johannes33bb23d2f3f6
diff --git a/src/components/App.tsx b/src/components/App.tsx
index b95d0c8f61..66880b64f2 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<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(