Skip to content
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

feat: support dragging when space is being pressed #212

Merged
merged 21 commits into from
Feb 28, 2023

Conversation

jimniels
Copy link
Collaborator

@jimniels jimniels commented Feb 3, 2023

Mimic Figma in how you can pan around the canvas

Feb-15-2023 17-13-22

How it works:

CleanShot 2023-02-24 at 18 25 14@2x

Todos:

  • Holding down spacebar switches cursor to grab
  • Holding down spacebar and mouse switches cursor to grabbing and allow panning
  • Letting go of spacebar/mouse gets you out of "panning mode"
  • If you're in "panning mode", taking the mouse outside of the grid keeps you in that mode
  • Add enums for pan mode

@aws-amplify-us-west-2
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-212.de5w5iglj13on.amplifyapp.com

@davidkircos
Copy link
Collaborator

davidkircos commented Feb 3, 2023

Do you have to set this flag to true?

https://github.com/quadratichq/quadratic/pull/212/files#diff-e3096530de99986094fddf045d3c58ac41adaf9ac648dae7e41d8b05822867c8R74

isMobileOnly will be false on every platform except mobile

@jimniels
Copy link
Collaborator Author

jimniels commented Feb 3, 2023

Ah yes, duh. That does make dragging work, but now there are other issues ha. For example:

  1. When you hold down spacebar and click to drag, the cell you click to drag gets selected (which we would want to prevent).
  2. Dragging outside the browser window changes from panning to selecting. I would expect it to continue to be panning.
  3. We would want to toggle the cursor when panning, e.g. when spacebar gets pressed down we would want to change the cursor to grab and then when we're dragging we would want to change it to grabbing.

These seems like controls or aspects of state that would need to come from pixi (??) and I'm not sure how to do them. Might have to leave this one until I can get help on it.

Feb-03-2023 09-30-22

@davidkircos
Copy link
Collaborator

davidkircos commented Feb 3, 2023 via email

@jimniels jimniels marked this pull request as draft February 6, 2023 18:03
@jimniels jimniels changed the base branch from development to main February 16, 2023 00:17
panMode: interactionState.panMode,
interactionState,
setInteractionState,
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best way to write this?

It feels cleaner, but does it mean that the event handlers (which need access to state in this component) don't get to use a closure for access the values and it causes unnecessary regeneration of the event handlers themselves?

React hooks trip me up here. But it does seem to work. I like the encapsulated logic but unsure if it's not idiomatic react.

@jimniels jimniels marked this pull request as ready for review February 26, 2023 01:29
@jimniels jimniels requested a review from davidkircos February 26, 2023 01:31
@davidkircos
Copy link
Collaborator

@jimniels drag no longer works on mobile

1 similar comment
@davidkircos
Copy link
Collaborator

@jimniels drag no longer works on mobile

@jimniels
Copy link
Collaborator Author

jimniels commented Feb 26, 2023

@davidkircos ah good catch. I needed to conditionally pass in the spacebar key for dragging Should work now.

@jimniels jimniels self-assigned this Feb 27, 2023
@davidkircos
Copy link
Collaborator

When you are typing into a cell, space still activates drag mode.

I think we just need to preventDefault on space here?
https://github.com/quadratichq/quadratic/blob/main/src/gridGL/interaction/CellInput.tsx#L193

@jimniels
Copy link
Collaborator Author

@davidkircos good catch on the cell input. Should've caught that. It's fixed now and ready for review once more

@jimniels jimniels merged commit adf072f into main Feb 28, 2023
@jimniels jimniels deleted the revert-211-revert-210-development-spacebar-drag branch February 28, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement spacebar for panning
3 participants