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

fix(Canvas): selection + setViewportTransform edge case #7713

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Feb 19, 2022

This PR handle the following edge case:
Say an object is being actively transformed by the user and at some point a call to setViewportTransform changes canvas vpt.
What happens prior to this PR is that the object jumps from the mouse because of the new vpt and then jumps back once the next event fires.
This is bad.
I think that setViewportTransform should not affect an active object that is being transformed.
It makes no sense.

https://gkpiim.csb.app/

Repro

http://jsfiddle.net/4zexwjo6/

  1. Select and hold an object OR transform it OR edit the text.
  2. After a few seconds canvas vpt changes and the object will move to another place
  3. You will experience an unwanted jump in transformation

To fix the fiddle change the cdn.

Before

ezgif com-gif-maker (20)

Expected Behavior

selected object should not be transformed by canvas vpt

After

ezgif com-gif-maker (21)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.34 |    76.75 |   86.53 |   83.07 |                                               
 fabric.js |   83.34 |    76.75 |   86.53 |   83.07 | ...,29680,29805,29885-29950,30073,30172,30389 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |    83.3 |    76.71 |   86.53 |   83.03 |                                               
 fabric.js |    83.3 |    76.71 |   86.53 |   83.03 | ...,29689,29814,29894-29959,30082,30181,30398 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur
Copy link
Member

asturur commented Feb 19, 2022

I m not sure what is going on, the explanations are scarce.
The vieportTransform shouldn't transform anything, is just a camera view over the canvas.
What is happening that is out of ordinary?

@ShaMan123
Copy link
Contributor Author

Take a look at the demo.
I hit an edge case a while back.
If you are transforming an object (say scaling or moving) and at the same moment the canvas vpt changes it affects the active object. Resulting in a jump once the next event is triggered.

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Feb 19, 2022

I am not sure about c1279b4 I have reverted it (say the canvas vpt is transformed while an active selection exists but is not actively transforming, the object becomes off screen and then the vpt is reversed and it's returned to screen)
What do you think?
Anyways if we decide it's in then we need to merge #7698 first (it calls isShadowOnScreen)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.28 |    76.65 |   86.53 |      83 |                                               
 fabric.js |   83.28 |    76.65 |   86.53 |      83 | ...,29708,29833,29913-29978,30101,30200,30417 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.36 |    76.75 |   86.54 |   83.09 |                                               
 fabric.js |   83.36 |    76.75 |   86.54 |   83.09 | ...,29705,29830,29910-29975,30098,30197,30414 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123
Copy link
Contributor Author

ready

@asturur
Copy link
Member

asturur commented Feb 20, 2022

image

Most of your demo get stuck hours like this.
I'm not sure why.

@ShaMan123
Copy link
Contributor Author

This is a repro http://jsfiddle.net/exabpkto/

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Feb 20, 2022

image

Most of your demo get stuck hours like this. I'm not sure why.

Probably because it's very heavy. fabric dist is copied to there. I plan to change that

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.21 |    76.58 |   86.39 |   82.93 |                                               
 fabric.js |   83.21 |    76.58 |   86.39 |   82.93 | ...,29887,30012,30092-30157,30280,30379,30596 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 force-pushed the selection-vpt-change-edge-case branch from dc335c1 to 5e3226b Compare March 2, 2022 08:18
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.31 |    76.72 |   86.53 |   83.04 |                                               
 fabric.js |   83.31 |    76.72 |   86.53 |   83.04 | ...,29701,29826,29906-29971,30094,30193,30410 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |    83.2 |    76.55 |   86.39 |   82.92 |                                               
 fabric.js |    83.2 |    76.55 |   86.39 |   82.92 | ...,29887,30012,30092-30157,30280,30379,30596 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.25 |    76.58 |   86.39 |   82.97 |                                               
 fabric.js |   83.25 |    76.58 |   86.39 |   82.97 | ...,29887,30012,30092-30157,30280,30379,30596 
-----------|---------|----------|---------|---------|-----------------------------------------------

@stale
Copy link

stale bot commented Mar 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Mar 18, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |    55.3 |    46.46 |   53.11 |   55.06 |                                               
 fabric.js |    55.3 |    46.46 |   53.11 |   55.06 | ...-30545,30627,30689,30700-30703,30726-30750 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.12 |    76.49 |   86.25 |   82.84 |                                               
 fabric.js |   83.12 |    76.49 |   86.25 |   82.84 | ...,29999,30124,30204-30269,30392,30491,30727 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.18 |    76.55 |   86.25 |   82.91 |                                               
 fabric.js |   83.18 |    76.55 |   86.25 |   82.91 | ...,29999,30124,30204-30269,30392,30491,30727 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.13 |    76.52 |   86.25 |   82.85 |                                               
 fabric.js |   83.13 |    76.52 |   86.25 |   82.85 | ...,29999,30124,30204-30269,30392,30491,30727 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.13 |    76.52 |   86.25 |   82.85 |                                               
 fabric.js |   83.13 |    76.52 |   86.25 |   82.85 | ...,29999,30124,30204-30269,30392,30491,30727 
-----------|---------|----------|---------|---------|-----------------------------------------------

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

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

Fixed the main issue and found and fixed a side effect that was causing tests to fail (stale _currentTransform ref on canvas)

@@ -1244,6 +1248,7 @@
return false;
}
this._activeObject = null;
this._currentTransform = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

crucial cleanup in case active object is during a transform

}
fabric.StaticCanvas.prototype.setViewportTransform.call(this, vpt);
this._setViewportTransform(vpt);
activeObject && activeObject.setCoords();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the following is sufficient because StaticCanvas sets coords on all objects

Suggested change
activeObject && activeObject.setCoords();
activeObject && activeObject.type === 'activeSelection' && activeObject.setCoords();

@ShaMan123 ShaMan123 requested a review from melchiar April 2, 2022 08:07
@fabricjs fabricjs deleted a comment from github-actions bot Apr 2, 2022
@ShaMan123
Copy link
Contributor Author

Updated description

This was referenced Apr 26, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.04 |    75.93 |   85.71 |   82.76 |                                               
 fabric.js |   83.04 |    75.93 |   85.71 |   82.76 | ...,30874,30948,30959-31024,31147,31246,31482 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 added the stale Issue marked as stale by the stale bot label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting evaluation feature stale Issue marked as stale by the stale bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants