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

Remove arrow key navigation temporarily so link boundaries work again #2453

Merged
merged 1 commit into from
Aug 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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