From 542151de7a2db693e63958335a57254127474e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Fri, 15 Mar 2019 15:07:31 +0100 Subject: [PATCH] Input Interaction: only consider selection at edge if directed towards it (#14450) * Input Interaction: only consider selection at edge if directed towards it * Add e2e test --- packages/dom/src/dom.js | 11 +++++++++++ .../multi-block-selection.test.js.snap | 6 ++++++ .../e2e-tests/specs/multi-block-selection.test.js | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/packages/dom/src/dom.js b/packages/dom/src/dom.js index 75f2d103113455..4ea9ad8c0ef78f 100644 --- a/packages/dom/src/dom.js +++ b/packages/dom/src/dom.js @@ -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; } diff --git a/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap b/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap index 3634f485a83ee8..dad6ac487081bc 100644 --- a/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap +++ b/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap @@ -9,3 +9,9 @@ exports[`Multi-block selection should only trigger multi-selection when at the e

" `; + +exports[`Multi-block selection should use selection direction to determine vertical edge 1`] = ` +" +

1
2.

+" +`; diff --git a/packages/e2e-tests/specs/multi-block-selection.test.js b/packages/e2e-tests/specs/multi-block-selection.test.js index 5a83abc74036d7..b65a7afa49b647 100644 --- a/packages/e2e-tests/specs/multi-block-selection.test.js +++ b/packages/e2e-tests/specs/multi-block-selection.test.js @@ -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(); + } ); } );