Skip to content

Commit

Permalink
fix: View mode wheel zooming does not work (excalidraw#8452)
Browse files Browse the repository at this point in the history
* Update App.tsx

* fix: prevent zooming browser over DOM

---------

Co-authored-by: dwelle <[email protected]>
  • Loading branch information
zsviczian and dwelle authored Aug 31, 2024
1 parent ee30225 commit 2d1d84a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ class App extends React.Component<AppProps, AppState> {
addEventListener(
this.excalidrawContainerRef.current,
EVENT.WHEEL,
this.onWheel,
this.handleWheel,
{ passive: false },
),
addEventListener(window, EVENT.MESSAGE, this.onWindowMessage, false),
Expand Down Expand Up @@ -4323,13 +4323,6 @@ class App extends React.Component<AppProps, AppState> {
},
);

private onWheel = withBatchedUpdates((event: WheelEvent) => {
// prevent browser pinch zoom on DOM elements
if (!(event.target instanceof HTMLCanvasElement) && event.ctrlKey) {
event.preventDefault();
}
});

private onKeyUp = withBatchedUpdates((event: KeyboardEvent) => {
if (event.key === KEYS.SPACE) {
if (this.state.viewModeEnabled) {
Expand Down Expand Up @@ -10089,6 +10082,11 @@ class App extends React.Component<AppProps, AppState> {
event.target instanceof HTMLIFrameElement
)
) {
// prevent zooming the browser (but allow scrolling DOM)
if (event[KEYS.CTRL_OR_CMD]) {
event.preventDefault();
}

return;
}

Expand Down

0 comments on commit 2d1d84a

Please sign in to comment.