-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support auto switching wheel behavior #4612
base: main
Are you sure you want to change the base?
Support auto switching wheel behavior #4612
Conversation
@trygveaa is attempting to deploy a commit to the tldraw Team on Vercel. A member of the Team first needs to authorize it. |
2 out of 2 authors have signed the CLA. Thanks! |
@@ -4,7 +4,7 @@ import { EASINGS } from './primitives/easings' | |||
/** @internal */ | |||
export const DEFAULT_CAMERA_OPTIONS: TLCameraOptions = { | |||
isLocked: false, | |||
wheelBehavior: 'pan', | |||
wheelBehavior: 'auto', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the default to auto
because I think that's the most intuitive behavior, but that's of course up to you if you want to do.
42f7653
to
2795d02
Compare
don't mind my test commits, we're testing something internally :) sry for the noise! |
No worries. And sorry for not signing the CLA yet, I had to talk to legal in my company (nothing particular about your CLA, just general policy for CLAs), but hopefully we'll get it sorted soon. |
@@ -9165,6 +9165,9 @@ export class Editor extends EventEmitter<TLEventMap> { | |||
/** @internal */ | |||
private _restoreToolId = 'select' | |||
|
|||
/** @internal */ | |||
private _autoWheelBehavior: 'pan' | 'zoom' = 'pan' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether the auto behavior starts off as pan
or zoom
should perhaps also be configurable.
It would also be nice to remember the last state the user was in in localstorage, so the same one can be used initially when loading the page again. Not sure if this is something tldraw should do automatically, or if it should emit an event on changes and allow this state to be set, so it can be implemented outside of tldraw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a config option for auto behavior and I added an event that is emitted when it's changed.
This implements support for setting wheelBehavior to auto. What this means is that it will try to detect if you're using a mouse or a touchpad, and use wheelBehavior zoom when a mouse is used and pan when a touchpad is used. This is more intuitive behavior than always having it set to wheel or pan in my opinion. As far as I know, it's unfortunately not possible to know if wheel events are generated from a mouse or a touchpad. The heuristic implemented is that if you scroll horizontally it assumes you use a touchpad and switch to pan, and if you pan with the middle mouse button it assumes you're using a mouse and switches to zoom. This seems to be similar to what other similar software does. Fixes tldraw#4579
9de45ae
to
c5caecb
Compare
wheelBehavior: 'zoom' | 'pan' | 'none' | ||
wheelBehavior: 'auto' | 'zoom' | 'pan' | 'none' | ||
/** The behavior used for the wheel when `wheelBehavior` is set to auto. */ | ||
autoWheelBehavior?: 'zoom' | 'pan' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it makes sense to have this in camera options?
f7f9f55
to
7e1d4a1
Compare
When `wheelBehavior` is set to `'auto'`, this controls whether the behavior used is `'pan'` or `'zoom'`. The value will automatically be changed on certain user interactions. Specifically it will change to `'pan'` when scrolling horizontally and change to `'zoom'` when the canvas is panned by either spacebar dragging or middle mouse dragging.
This allows you to listen to changes to `autoWheelBehavior` and store it in e.g. local storage so you can initialize it to the same value the next time tldraw is laoded.
The reason for this is that pinch to zoom on a touchpad generates vertical scroll events with ctrlKey set to true.
7e1d4a1
to
b590dea
Compare
/huppy check cla |
Sorry for some spam here, testing out the logic to skip some of our checks for external contributors. |
This implements support for setting wheelBehavior to auto. What this means is that it will try to detect if you're using a mouse or a touchpad, and use wheelBehavior zoom when a mouse is used and pan when a touchpad is used. This is more intuitive behavior than always having it set to wheel or pan in my opinion.
As far as I know, it's unfortunately not possible to know if wheel events are generated from a mouse or a touchpad. The heuristic implemented is that if you scroll horizontally it assumes you use a touchpad and switch to pan, and if you pan with the middle mouse button it assumes you're using a mouse and switches to zoom. This seems to be similar to what other similar software does.
Fixes #4579
Change type
bugfix
improvement
feature
api
other
Test plan
Release notes
pan
when using a touchpad andzoom
when using a mouse.