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

Input Interaction: only consider selection at edge if directed towards it #14450

Merged
merged 2 commits into from Mar 15, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/dom/src/dom.js
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
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
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();
} );
} );