Skip to content

Commit

Permalink
Remove arrow key navigation temporarily so link boundaries work again (
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and mtias committed Aug 18, 2017
1 parent 20d0a13 commit be9cb7b
Showing 1 changed file with 1 addition and 52 deletions.
53 changes: 1 addition & 52 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
getMultiSelectedBlockUids,
} from '../../selectors';

const { BACKSPACE, ESCAPE, DELETE, UP, DOWN, LEFT, RIGHT, ENTER } = keycodes;
const { BACKSPACE, ESCAPE, DELETE, ENTER } = keycodes;

function FirstChild( { children } ) {
const childrenArray = Children.toArray( children );
Expand All @@ -73,7 +73,6 @@ class VisualEditorBlock extends Component {
this.onPointerDown = this.onPointerDown.bind( this );
this.onKeyDown = this.onKeyDown.bind( this );
this.onKeyUp = this.onKeyUp.bind( this );
this.handleArrowKey = this.handleArrowKey.bind( this );
this.toggleMobileControls = this.toggleMobileControls.bind( this );
this.onBlockError = this.onBlockError.bind( this );

Expand Down Expand Up @@ -252,13 +251,6 @@ class VisualEditorBlock extends Component {
onKeyDown( event ) {
const { keyCode, target } = event;

this.handleArrowKey( event );

if ( keyCode === UP || keyCode === LEFT || keyCode === DOWN || keyCode === RIGHT ) {
const selection = window.getSelection();
this.lastRange = selection.rangeCount ? selection.getRangeAt( 0 ) : null;
}

if ( ENTER === keyCode && target === this.node ) {
event.preventDefault();

Expand All @@ -270,49 +262,6 @@ class VisualEditorBlock extends Component {

onKeyUp( event ) {
this.removeOrDeselect( event );
this.handleArrowKey( event );
}

handleArrowKey( event ) {
const { keyCode, target } = event;
const moveUp = ( keyCode === UP || keyCode === LEFT );
const moveDown = ( keyCode === DOWN || keyCode === RIGHT );
const wrapperClassname = '.editor-visual-editor';
const selectors = [
'*[contenteditable="true"]',
'*[tabindex]',
'textarea',
'input',
].map( ( selector ) => `${ wrapperClassname } ${ selector }` ).join( ',' );

if ( moveUp || moveDown ) {
const selection = window.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

// If there's no movement, so we're either at the end of start, or
// no text input at all.
if ( range !== this.lastRange ) {
return;
}

const focusableNodes = Array.from( document.querySelectorAll( selectors ) );

if ( moveUp ) {
focusableNodes.reverse();
}

const targetNode = focusableNodes
.slice( focusableNodes.indexOf( target ) )
.reduce( ( result, node ) => {
return result || ( node.contains( target ) ? null : node );
}, null );

if ( targetNode ) {
targetNode.focus();
}
}

delete this.lastRange;
}

toggleMobileControls() {
Expand Down

0 comments on commit be9cb7b

Please sign in to comment.