Fix cropping tools in the block editor #6909
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Fixes cropping tools in the block editor. Related Gutenberg issue: WordPress/gutenberg#62855.
Why
Currently, the cropping tool in the block editor doesn't apply the selected crop.
As of 4f175e1 / #6876, the width and height cropping values are rounded and cast to an
int
before the comparison to see if the target width and height differ from the original width and height.Since they are now
int
s, it exposes a bug where the&&
of theif
conditional meant that if you were only cropping in one dimension, the check wouldn't pass, and cropping would not occur.In the block editor, the cropping tools are aspect ratio based, so one of the dimensions will always match that of the source image. Therefore, now that the values are cast as
int
s, we need to update the condition that allows a cropping to occur. In this case, I believe it should be||
instead of&&
. If either width or height is different from the source image, then we should allow a crop.How to test
Trac ticket: https://core.trac.wordpress.org/ticket/61514
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.