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

No guarantee for event order will be exactly: pointerDown -> pointerMove -> pointerUp #7

Open
pobch opened this issue Apr 10, 2022 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@pobch
Copy link
Owner

pobch commented Apr 10, 2022

Example cases:

  1. Line tool
  2. Click & Hold a mouse inside <canvas/>
  3. Move the cursor out of the viewport (still holding click)
  4. Release click outside the viewport
  5. Move the cursor back to the viewport
  6. Click Undo
  7. Unhandled errors occur while moving the cursor

The order in this case:
pointerDown (canvas)
-> pointerMove (inside to outside canvas)
-> pointerMove (back to canvas)
-> onClick (undo button)
-> pointerMove (canvas)
-> pointerDown (canvas)
-> pointerUp (canvas)

line.mp4
pencil.mp4
rect.mp4

Possible Solutions

We should combine multiple techniques together.

Technique 1

  • Excalidraw calls onPointerUp handler when the mouse is moved out of canvas in the middle of drawing. How? maybe they use onPointerOut, onPointerLeave ??

Technique 2

  • Excalidraw: they set pointer-events: none to all floating buttons, e.g. undo button, while the user starts dragging an element in the canvas.

Technique 3

  • In every event handler, first check for an expected state before proceed any actions. For unexpected/uninterested state, do nothing. (i.e. Finite state machine)
    • pointerDown (canvas): expected none state, proceed changing to drawing state
      -> pointerMove (inside to outside canvas): expected drawing state, proceed logic
      -> release a pointer outside canvas
      -> pointerMove (back to canvas): expected drawing state, proceed logic
      -> pointerDown (canvas): unexpected drawing state, do nothing
      -> pointerMove (canvas): expected drawing state, proceed logic
      -> pointerUp (canvas): expected drawing state, proceed changing to none state
  • Other than previous state name, also beware of data that comes from previous state. Don't assume any previous data. Instead, always check if data is valid, e.g. check if id of element we are editing is valid. (i.e. Make sure every event handler is stateless and independent from any previous event handlers)
@pobch pobch added the bug Something isn't working label Apr 10, 2022
@pobch pobch changed the title Bug: No guarantee order that pointerUp will be triggered after pointerDown No guarantee that events order will be exactly: pointerDown -> pointerMove -> pointerUp Apr 10, 2022
@pobch pobch removed the bug Something isn't working label May 4, 2022
@pobch pobch changed the title No guarantee that events order will be exactly: pointerDown -> pointerMove -> pointerUp Bug: No guarantee for event order will be exactly: pointerDown -> pointerMove -> pointerUp May 4, 2022
@pobch pobch changed the title Bug: No guarantee for event order will be exactly: pointerDown -> pointerMove -> pointerUp No guarantee for event order will be exactly: pointerDown -> pointerMove -> pointerUp May 19, 2022
@pobch pobch added the bug Something isn't working label May 19, 2022
@pobch
Copy link
Owner Author

pobch commented May 19, 2022

Another example case

pointerDown -> pointerUp (without passing through pointerMove)

@pobch pobch added the experiment Experiment for new tools or approaches label May 29, 2022
@pobch pobch added help wanted Extra attention is needed and removed experiment Experiment for new tools or approaches labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant