Skip to content

Commit

Permalink
Fix: Make ⌘A's select all the blocks again (#7731)
Browse files Browse the repository at this point in the history
* Fix: Make ⌘A's select all the blocks again

Moves the logic to handle meta+a to be before the check for event.nativeEvent.defaultPrevented. The event was default prevented by TinyMCE.

* Add e2e test
  • Loading branch information
jorgefilipecosta committed Jul 6, 2018
1 parent 87252f2 commit c33bb2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
28 changes: 15 additions & 13 deletions editor/components/writing-flow/index.js
Expand Up @@ -188,12 +188,6 @@ class WritingFlow extends Component {
onKeyDown( event ) {
const { hasMultiSelection, onMultiSelect, blocks } = this.props;

// Aobrt if navigation has already been handled (e.g. TinyMCE inline
// boundaries).
if ( event.nativeEvent.defaultPrevented ) {
return;
}

const { keyCode, target } = event;
const isUp = keyCode === UP;
const isDown = keyCode === DOWN;
Expand All @@ -204,15 +198,11 @@ class WritingFlow extends Component {
const isVertical = isUp || isDown;
const isNav = isHorizontal || isVertical;
const isShift = event.shiftKey;

const isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;

if ( ! isVertical ) {
this.verticalRect = null;
} else if ( ! this.verticalRect ) {
this.verticalRect = computeCaretRect( target );
}

// This logic inside this condition needs to be checked before
// the check for event.nativeEvent.defaultPrevented.
// The logic handles meta+a keypress and this event is default prevented by TinyMCE.
if ( ! isNav ) {
// Set immediately before the meta+a combination can be pressed.
if ( isKeyboardEvent.primary( event ) ) {
Expand All @@ -236,6 +226,18 @@ class WritingFlow extends Component {
return;
}

// Abort if navigation has already been handled (e.g. TinyMCE inline
// boundaries).
if ( event.nativeEvent.defaultPrevented ) {
return;
}

if ( ! isVertical ) {
this.verticalRect = null;
} else if ( ! this.verticalRect ) {
this.verticalRect = computeCaretRect( target );
}

if ( isShift && ( hasMultiSelection || (
this.isTabbableEdge( target, isReverse ) &&
isNavEdge( target, isReverse, true )
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/specs/multi-block-selection.test.js
Expand Up @@ -66,5 +66,11 @@ describe( 'Multi-block selection', () => {

// No selection
await expectMultiSelected( blocks, false );

// Select all via double shortcut.
await page.click( firstBlockSelector );
await pressWithModifier( 'Mod', 'a' );
await pressWithModifier( 'Mod', 'a' );
await expectMultiSelected( blocks, true );
} );
} );

0 comments on commit c33bb2a

Please sign in to comment.