Skip to content

Commit

Permalink
Block Toolbar: Replace alt with command and support alt + f10
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 11, 2017
1 parent d30c367 commit 3a573dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions editor/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import BlockRightMenu from '../block-settings-menu';
/**
* Module Constants
*/
const { LEFT, RIGHT, ESCAPE, ALT } = keycodes;
const { LEFT, RIGHT, ESCAPE, F10, isMetaKey } = keycodes;

function FirstChild( { children } ) {
const childrenArray = Children.toArray( children );
Expand Down Expand Up @@ -72,7 +72,7 @@ class BlockToolbar extends Component {
const tabbables = focus.tabbable.find( this.toolbar );
const indexOfTabbable = tabbables.indexOf( document.activeElement );

if ( event.keyCode === ALT ) {
if ( isMetaKey( event.keyCode ) || ( event.keyCode === F10 && event.altKey ) ) {
if ( tabbables.length ) {
tabbables[ 0 ].focus();
}
Expand Down
18 changes: 18 additions & 0 deletions utils/keycodes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const BACKSPACE = 8;
export const TAB = 9;
export const ENTER = 13;
export const CTRL = 17;
export const ALT = 18;
export const ESCAPE = 27;
export const SPACE = 32;
Expand All @@ -9,3 +10,20 @@ export const UP = 38;
export const RIGHT = 39;
export const DOWN = 40;
export const DELETE = 46;

export const F10 = 121;

export const MAC_RIGHT = 93;
export const MAC_LEFT = 91;
export const MAC_FIREFOX = 224;

function isMac() {
return window.navigator.platform.toLowerCase().indexOf( 'mac' ) !== -1;
}

export function isMetaKey( keyCode ) {
return isMac()
// The keyCode depends on the browser and the left/right might be different
? [ MAC_FIREFOX, MAC_LEFT, MAC_RIGHT ].indexOf( keyCode ) !== -1
: CTRL;
}

0 comments on commit 3a573dc

Please sign in to comment.