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

Plugin: Backport bug fixes from Gutenberg 5.5.0 to wp/trunk (WordPress 5.2 RC) (Part 2) #15020

Merged
merged 8 commits into from
Apr 17, 2019
26 changes: 13 additions & 13 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -415,36 +415,34 @@
z-index: z-index(".block-editor-block-list__block {core/image aligned wide or fullwide}");

// Mover and settings above
> .block-editor-block-mover {
&.is-multi-selected > .block-editor-block-mover,
> .block-editor-block-list__block-edit > .block-editor-block-mover {
// This moves the menu up by the height of the button + border + padding.
top: -$block-side-ui-width - $block-padding - $block-side-ui-clearance;
bottom: auto;
min-height: 0;
height: auto;
width: auto;
z-index: inherit;

&::before {
content: none;
}
}

> .block-editor-block-mover .block-editor-block-mover__control {
&.is-multi-selected > .block-editor-block-mover .block-editor-block-mover__control,
> .block-editor-block-list__block-edit > .block-editor-block-mover .block-editor-block-mover__control {
float: left;
}

// Position hover label on the right
> .block-editor-block-list__breadcrumb {
right: -$border-width;
}

// Hide mover until wide breakpoints, or it might be covered by toolbar
> .block-editor-block-mover {
&.is-multi-selected > .block-editor-block-mover,
> .block-editor-block-list__block-edit > .block-editor-block-mover {
display: none;
}

@include break-wide() {
> .block-editor-block-mover {
&.is-multi-selected > .block-editor-block-mover,
> .block-editor-block-list__block-edit > .block-editor-block-mover {
display: block;
}
}
Expand All @@ -461,7 +459,8 @@
// Wide
&[data-align="wide"] {
// Position mover
> .block-editor-block-mover {
&.is-multi-selected > .block-editor-block-mover,
> .block-editor-block-list__block-edit > .block-editor-block-mover {
left: -$block-padding + $border-width;
}
}
Expand Down Expand Up @@ -503,7 +502,8 @@
}

// Position mover
> .block-editor-block-mover {
&.is-multi-selected > .block-editor-block-mover,
> .block-editor-block-list__block-edit > .block-editor-block-mover {
left: $border-width;
}
}
Expand Down Expand Up @@ -913,7 +913,7 @@
}
}

.block-editor-block-list__block.is-focus-mode:not(.is-multi-selected) > .block-editor-block-contextual-toolbar {
.block-editor-block-list__block.is-focus-mode:not(.is-multi-selected) > .block-editor-block-list__block-edit > .block-editor-block-contextual-toolbar {
margin-left: -$block-side-ui-width;
}

Expand Down
17 changes: 14 additions & 3 deletions packages/dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ function isEdge( container, isReverse, onlyVertical ) {
return false;
}

const rangeRect = getRectangleFromRange( selection.getRangeAt( 0 ) );
const range = selection.getRangeAt( 0 ).cloneRange();
const isForward = isSelectionForward( selection );
const isCollapsed = selection.isCollapsed;

// Collapse in direction of selection.
if ( ! isCollapsed ) {
range.collapse( ! isForward );
}

const rangeRect = getRectangleFromRange( range );

if ( ! rangeRect ) {
return false;
Expand All @@ -105,9 +114,9 @@ function isEdge( container, isReverse, onlyVertical ) {
// Only consider the multiline selection at the edge if the direction is
// towards the edge.
if (
! selection.isCollapsed &&
! isCollapsed &&
rangeRect.height > lineHeight &&
isSelectionForward( selection ) === isReverse
isForward === isReverse
) {
return false;
}
Expand Down Expand Up @@ -213,6 +222,8 @@ export function getRectangleFromRange( range ) {
// See: https://stackoverflow.com/a/6847328/995445
if ( ! rect ) {
const padNode = document.createTextNode( '\u200b' );
// Do not modify the live range.
range = range.cloneRange();
range.insertNode( padNode );
rect = range.getClientRects()[ 0 ];
padNode.parentNode.removeChild( padNode );
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,13 @@ exports[`adding blocks should not delete surrounding space when deleting a word
<p>1 2 3</p>
<!-- /wp:paragraph -->"
`;

exports[`adding blocks should not prematurely multi-select 1`] = `
"<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>></p>
<!-- /wp:paragraph -->"
`;
1 change: 0 additions & 1 deletion packages/e2e-tests/specs/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe( 'adding blocks', () => {
await page.keyboard.type( 'Foo' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'ArrowUp' );
await pressKeyTimes( 'ArrowRight', 3 );
await pressKeyTimes( 'Delete', 6 );
await page.keyboard.type( ' text' );

Expand Down
15 changes: 15 additions & 0 deletions packages/e2e-tests/specs/writing-flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,19 @@ describe( 'adding blocks', () => {

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not prematurely multi-select', async () => {
await clickBlockAppender();
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '><<' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '<<<' );
await page.keyboard.down( 'Shift' );
await pressKeyTimes( 'ArrowLeft', '<<\n<<<'.length );
await page.keyboard.up( 'Shift' );
await page.keyboard.press( 'Backspace' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
3 changes: 2 additions & 1 deletion packages/edit-post/src/components/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
margin-right: -$block-side-ui-width;
}

// Center the block toolbar on full-wide blocks.
// Center the block toolbar on wide and full-wide blocks.
// Use specific selector to not affect nested block toolbars.
&[data-align="wide"] > .block-editor-block-list__block-edit > .block-editor-block-contextual-toolbar,
&[data-align="full"] > .block-editor-block-list__block-edit > .block-editor-block-contextual-toolbar {
height: 0; // This collapses the container to an invisible element without margin.
width: 100%;
Expand Down