From 92aefd35bba78b40a371f856334e277dcc3c04c0 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 12 Apr 2019 15:21:51 +0300 Subject: [PATCH] adds docs correction to correspond, adds inlined script to remove production dead code --- docs/designers-developers/faq.md | 8 +++--- .../src/keyboard-shortcuts/index.js | 26 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/docs/designers-developers/faq.md b/docs/designers-developers/faq.md index 4917ac8f82e3c1..9bd9c8fae2530a 100644 --- a/docs/designers-developers/faq.md +++ b/docs/designers-developers/faq.md @@ -102,13 +102,13 @@ This is the canonical list of keyboard shortcuts: Navigate to a the next part of the editor (alternative). - Shift+Alt+N - N + Ctrl+Alt+N + N Navigate to the previous part of the editor (alternative). - Shift+Alt+P - P + Ctrl+Alt+P + P Navigate to the nearest toolbar. diff --git a/packages/components/src/keyboard-shortcuts/index.js b/packages/components/src/keyboard-shortcuts/index.js index 587d181e3326e4..d4b12867e08b6f 100644 --- a/packages/components/src/keyboard-shortcuts/index.js +++ b/packages/components/src/keyboard-shortcuts/index.js @@ -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 ); @@ -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;