Skip to content

Commit

Permalink
Input Interaction: only consider selection at edge if directed toward…
Browse files Browse the repository at this point in the history
…s it (#14450)

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

* Add e2e test
  • Loading branch information
ellatrix authored Mar 15, 2019
1 parent 6c8486f commit 542151d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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.
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();
} );
} );

0 comments on commit 542151d

Please sign in to comment.