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

Selection box cause an error #867

Closed
rougsig opened this issue Jul 16, 2021 · 3 comments · Fixed by #871
Closed

Selection box cause an error #867

rougsig opened this issue Jul 16, 2021 · 3 comments · Fixed by #871

Comments

@rougsig
Copy link

rougsig commented Jul 16, 2021

Steps to reproduce:

  1. Go to demo
  2. Try to select with box (shift + mouse click)
  3. See error in the console:
    Firefox: Uncaught ReferenceError: TouchEvent is not defined
    Chrome: Uncaught TypeError: Cannot read properties of undefined (reading 'x')

Expected result:
Selection box is visible and select nodes.

@rougsig
Copy link
Author

rougsig commented Jul 16, 2021

Bug is here.

@vadimshvetsov
Copy link
Contributor

vadimshvetsov commented Jul 22, 2021

It comes from #828 . I'm ready to PR something like this:

getBoxDimensions(event: AbstractDisplacementStateEvent): ClientRect {
		let rel: Point;
	        if (event.event.touches) {
		  const touch = event.event.touches[0];
		  rel = this.engine.getRelativePoint(touch.clientX, touch.clientY);
		} else {
                  rel = this.engine.getRelativePoint(event.event.clientX, event.event.clientY)
                }
                ...
	}

So I'm suggesting to use second path by default instead of assuming that it is MouseEvent. Do you have better idea for fast fix @renato-bohler ?

It looks like React.MouseEvent is a TS type. I'm not sure that it can be used with instanceof. We can use event.event.nativeEvent and instanceof native event as second option.

@renato-bohler
Copy link
Contributor

It comes from #828 . I'm ready to PR something like this:

getBoxDimensions(event: AbstractDisplacementStateEvent): ClientRect {
		let rel: Point;
	        if (event.event.touches) {
		  const touch = event.event.touches[0];
		  rel = this.engine.getRelativePoint(touch.clientX, touch.clientY);
		} else {
                  rel = this.engine.getRelativePoint(event.event.clientX, event.event.clientY)
                }
                ...
	}

So I'm suggesting to use second path by default instead of assuming that it is MouseEvent. Do you have better idea for fast fix @renato-bohler ?

It looks like React.MouseEvent is a TS type. I'm not sure that it can be used with instanceof. We can use event.event.nativeEvent and instanceof native event as second option.

Hmm, it's weird that this same code works on my project... but well, it seems to me that your change will address that issue.

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 a pull request may close this issue.

3 participants