Skip to content
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
11 changes: 11 additions & 0 deletions packages/dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ export function isVerticalEdge( container, isReverse ) {
}

const selection = window.getSelection();

// Only consider the selection at the edge if the direction is towards the
// edge.
Copy link
Member

Choose a reason for hiding this comment

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

Love the dedication to the 80 column 👍

if (
! selection.isCollapsed &&
isSelectionForward( selection ) === isReverse
) {
return false;
}

const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

if ( ! range ) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ exports[`Multi-block selection should only trigger multi-selection when at the e
<p></p>
<!-- /wp:paragraph -->"
`;

exports[`Multi-block selection should use selection direction to determine vertical edge 1`] = `
"<!-- wp:paragraph -->
<p>1<br>2.</p>
<!-- /wp:paragraph -->"
`;
15 changes: 15 additions & 0 deletions packages/e2e-tests/specs/multi-block-selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,19 @@ describe( 'Multi-block selection', () => {

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

it( 'should use selection direction to determine vertical edge', async () => {
await clickBlockAppender();
await page.keyboard.type( '1' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '2' );

await pressKeyWithModifier( 'shift', 'ArrowUp' );
await pressKeyWithModifier( 'shift', 'ArrowDown' );

// Should type at the end of the paragraph.
await page.keyboard.type( '.' );

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