Use meta key + wheel to zoom in/out (#769)

This commit is contained in:
Timur Khazamov 2020-02-16 14:38:53 +01:00 committed by GitHub
parent 360864ef3d
commit eee961d65f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View file

@ -35,6 +35,7 @@ import {
calculateScrollCenter,
loadFromBlob,
getZoomOrigin,
getNormalizedZoom,
} from "./scene";
import { renderScene } from "./renderer";
@ -1983,10 +1984,17 @@ export class App extends React.Component<any, AppState> {
e.preventDefault();
const { deltaX, deltaY } = e;
this.setState({
scrollX: this.state.scrollX - deltaX / this.state.zoom,
scrollY: this.state.scrollY - deltaY / this.state.zoom,
});
if (e[KEYS.META]) {
this.setState(({ zoom }) => ({
zoom: getNormalizedZoom(zoom - deltaY / 100),
}));
return;
}
this.setState(({ zoom, scrollX, scrollY }) => ({
scrollX: scrollX - deltaX / zoom,
scrollY: scrollY - deltaY / zoom,
}));
};
private addElementsFromPaste = (