-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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/resizing images by dragging #7376
Conversation
core-blocks/image/edit.js
Outdated
@@ -344,6 +344,7 @@ class ImageEdit extends Component { | |||
const ratio = imageWidth / imageHeight; | |||
const minWidth = imageWidth < imageHeight ? MIN_SIZE : MIN_SIZE * ratio; | |||
const minHeight = imageHeight < imageWidth ? MIN_SIZE : MIN_SIZE / ratio; | |||
const isRLT = window.getComputedStyle( document.querySelector( '.editor-block-list__layout' ) ).direction === 'rtl'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be getting state from DOM. Can use selector for it within withSelect:
isRTL: select( 'core/editor' ).getEditorSettings().isRTL,
Then access as prop.isRTL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, was looking at that. RTL is a bit of a special case. getComputedStyle()
has the advantage of catching both the dir
attribute and CSS direction
, and dynamically gets the proper state used at the moment.
The dir
attribute is usually set the same as the editor setting but in some cases may be reversed (including from the CSS direction
). For example the code
block in RTL languages should still be LTR. I agree this generally wouldn't apply to image blocks, so using the editor setting should be sufficient.
Also it seems we don't yet have good RTL support. The classic editor gets an additional button in RTL languages that lets the user reverse text direction. We'll probably need to add that in most blocks with RichText
, and set the code
block to LTR by default.
core-blocks/image/edit.js
Outdated
@@ -346,6 +346,9 @@ class ImageEdit extends Component { | |||
const minWidth = imageWidth < imageHeight ? MIN_SIZE : MIN_SIZE * ratio; | |||
const minHeight = imageHeight < imageWidth ? MIN_SIZE : MIN_SIZE / ratio; | |||
|
|||
const showRightHandle = ( isRTL && ( align === 'left' || align === 'center' ) || ! isRTL && align !== 'right' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here feels a bit hard to read. Any way to make it more readable? Guessing it could read something like, if it's aligned centre both handles should show, otherwise show right or left depending on isRTL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There also seems to be a linting error:
[0] /home/travis/build/WordPress/gutenberg/core-blocks/image/edit.js
[0] 349:40 error Unexpected mix of '&&' and '||' no-mixed-operators
[0] 349:86 error Unexpected mix of '&&' and '||' no-mixed-operators
[0] 349:86 error Unexpected mix of '||' and '&&' no-mixed-operators
[0] 349:97 error Unexpected mix of '||' and '&&' no-mixed-operators
[0] 350:39 error Unexpected mix of '&&' and '||' no-mixed-operators
[0] 350:59 error Unexpected mix of '&&' and '||' no-mixed-operators
[0] 350:59 error Unexpected mix of '||' and '&&' no-mixed-operators
[0] 350:70 error Unexpected mix of '||' and '&&' no-mixed-operators
[0]
[0] ✖ 8 problems (8 errors, 0 warnings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected mix of '&&' and '||' no-mixed-operators
Ha, why am I not seeing these here... Also... "unexpected"... in parentheses..? What is that rule, lol.
Yeah, it is a bit hard to read, can change that to a "proper" if()
block. I know, wordy, but oh well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... How do you "unblock" that linter when:
if ( true && ( true || false ) )
would always have a mix of &&
and ||
. This looks like a bug there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's catching the last bit: || ! isRTL && align !== 'right'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case it wouldn't hurt to be a bit more readable :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, an if()
block would be better there.
Might be good to leave a comment for the next person trying to add corner handles back, pointing at the limitation of the resizable component at this time. |
Interestingly there's both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me provided tests pass.
Ha, are these conflicting linting rules? Can't do
because there are
because of single nested if. Hmm, is that "linting vs. readability"? :) |
@iseulde There are some illustrations here that show the difference between https://developer.mozilla.org/en-US/docs/Web/CSS/cursor I would say that |
See #7375.