Skip to content

Commit

Permalink
adds docs correction to correspond, adds inlined script to remove pro…
Browse files Browse the repository at this point in the history
…duction dead code
  • Loading branch information
draganescu committed Apr 12, 2019
1 parent cd58e41 commit 92aefd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/designers-developers/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ This is the canonical list of keyboard shortcuts:
</tr>
<tr>
<td>Navigate to a the next part of the editor (alternative).</td>
<td><kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>N</kbd></td>
<td><kbd></kbd><kbd>⌥</kbd><kbd>N</kbd></td>
<td><kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>N</kbd></td>
<td><kbd></kbd><kbd>⌥</kbd><kbd>N</kbd></td>
</tr>
<tr>
<td>Navigate to the previous part of the editor (alternative).</td>
<td><kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>P</kbd></td>
<td><kbd></kbd><kbd>⌥</kbd><kbd>P</kbd></td>
<td><kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>P</kbd></td>
<td><kbd></kbd><kbd>⌥</kbd><kbd>P</kbd></td>
</tr>
<tr>
<td>Navigate to the nearest toolbar.</td>
Expand Down
26 changes: 11 additions & 15 deletions packages/components/src/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ import { forEach } from 'lodash';
*/
import { Component, Children } from '@wordpress/element';

function throwForInvalidCombination( combination ) {
const keys = combination.split( '+' );
const modifiers = new Set( keys.filter( ( value ) => value.length > 1 ) );
const hasAlt = modifiers.has( 'alt' );
const hasShift = modifiers.has( 'shift' );

if (
( modifiers.size === 1 && hasAlt ) ||
( modifiers.size === 2 && hasAlt && hasShift )
) {
throw new Error( `Cannot bind ${ combination }. Alt and Shift+Alt modifiers are reserved for character input.` );
}
}

class KeyboardShortcuts extends Component {
constructor() {
super( ...arguments );
Expand All @@ -38,7 +24,17 @@ class KeyboardShortcuts extends Component {

forEach( this.props.shortcuts, ( callback, key ) => {
if ( process.env.NODE_ENV === 'development' ) {
throwForInvalidCombination( key );
const keys = key.split( '+' );
const modifiers = new Set( keys.filter( ( value ) => value.length > 1 ) );
const hasAlt = modifiers.has( 'alt' );
const hasShift = modifiers.has( 'shift' );

if (
( modifiers.size === 1 && hasAlt ) ||
( modifiers.size === 2 && hasAlt && hasShift )
) {
throw new Error( `Cannot bind ${ key }. Alt and Shift+Alt modifiers are reserved for character input.` );
}
}

const { bindGlobal, eventName } = this.props;
Expand Down

0 comments on commit 92aefd3

Please sign in to comment.