tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
33.4k stars 1.99k forks source link

Enable panning for all tools #484

Closed csenio closed 2 years ago

csenio commented 2 years ago

closes tldraw/tldraw-v1#318

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

core – ./

🔍 Inspect: https://vercel.com/tldraw/core/BhmjD86A85Mh9ENkjZRp1QtGoZE9
✅ Preview: https://core-git-fork-jescowuester-feature-global-panning-tldraw.vercel.app

tldraw – ./

🔍 Inspect: https://vercel.com/tldraw/tldraw/61A2CtdXnqXRwmLE19Q4dYTXBaen
✅ Preview: https://tldraw-git-fork-jescowuester-feature-global-panning-tldraw.vercel.app

csenio commented 2 years ago

Should be done. Should I write tests for this somewhere?

steveruizok commented 2 years ago

I like it! The only place where I was able to break it was inside of an active text field: I could hold space and click and drag at the same time to pan while editing, though this is an admittedly weird interaction. This is mostly due to the lack of an "editing" state, which has been on the todo list for a while, so we'll fix it when we fix that.

steveruizok commented 2 years ago

Also able to pan while the context menu is open. Again, kind of a weird interaction so I'll let it go for the moment.

steveruizok commented 2 years ago

I think I found a good solution here, pushing some changes and tests.

steveruizok commented 2 years ago

Want to test this out @jescowuester?

I'm using the term "force panning" for panning while spacebar or middle mouse wheel is pressed.

Force panning now works regardless of any tool state. You can, for example, start resizing a shape, press spacebar and move the camera, then continue resizing the shape. Same for dragging, etc. I think this is ultimately what we're after with this kind of gesture!

csenio commented 2 years ago

@steveruizok I like it in theory, but I think this approach means we will have to handle a lot more edge cases. Here are 2 I just found:

tools can be accidentally triggered while panning (eraser, sticky & text)

https://user-images.githubusercontent.com/43379421/148203940-dfa07f18-4dcd-4605-bf72-3ee33e9e54ee.mov

pressing "space" triggers the buttons in the toolbar (think we just need to change the variables I used to disable those buttons)

https://user-images.githubusercontent.com/43379421/148204173-fcadf8fa-e55d-4275-a492-55b8f0fa1428.mov

We could probably disable all interactions while force dragging and then select a couple of desirable ones (like resizing a shape) to selectively enable. Not sure if it's worth the extra trouble though (I personally just let go of the shape when I want to pan my camera)

steveruizok commented 2 years ago

Great catches!

steveruizok commented 2 years ago

Merged! Thanks again @jescowuester .

csenio commented 2 years ago

@steveruizok don't think Prevent default on tool buttons keydown if forcePanning worked, still having that same flicker

https://user-images.githubusercontent.com/43379421/148767771-a3d2eb59-e4e0-4e6d-a390-c723f248efb1.mov

steveruizok commented 2 years ago

I can't reproduce it here, but I'll take another look!