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 inbetween-inserter position in RTL languages #49683

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useRefEffect } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useContext } from '@wordpress/element';
import { isRTL } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -93,7 +94,9 @@ export function useInBetweenInserter() {
blockElRect.top > offsetTop ) ||
( blockEl.classList.contains( 'wp-block' ) &&
orientation === 'horizontal' &&
blockElRect.left > offsetLeft )
( isRTL()
? blockElRect.right < offsetLeft
: blockElRect.left > offsetLeft ) )
);
} );

Expand Down
15 changes: 2 additions & 13 deletions packages/block-editor/src/components/block-popover/inbetween.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,7 @@ function BlockPopoverInbetween( {
nextRect && previousRect
? nextRect.top - previousRect.bottom
: 0;

if ( isRTL() ) {
// vertical, rtl
left = previousRect
? previousRect.right
: nextRect.right;
} else {
// vertical, ltr
left = previousRect ? previousRect.left : nextRect.left;
}
left = previousRect ? previousRect.left : nextRect.left;
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why was the isRTL() check here unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just imagine this visually.

In LTR languages, the previous element is on the left of the next element but in RTL it's on the right. meaning that if we want to position a "div" between the two elements, its "left" coordinate should be the "right" coordinate of the "previous" element in LTR but it should be the "left" coordinate of the "next" element in RTL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I guess the question here is the "opposite". It's unnecessary here because in the case of the "vertical" in-between inserter, the "left" position is the same for both blocks anyway, so the left position of the empty space between them is also the same "left" position, so either prev.left or next.left. (and shouldn't be right in any case)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation — it makes sense to remove the RTL check for the vertical inserter :)

} else {
top = previousRect ? previousRect.top : nextRect.top;
height = previousRect
Expand All @@ -124,9 +115,7 @@ function BlockPopoverInbetween( {

if ( isRTL() ) {
// non vertical, rtl
left = previousRect
? previousRect.left
: nextRect.right;
left = nextRect ? nextRect.right : previousRect.left;
width =
previousRect && nextRect
? previousRect.left - nextRect.right
Expand Down