Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 17, 2018
1 parent 426d8ca commit ebac53e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions utils/keycodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export const DELETE = 46;

export const F10 = 121;

/**
* Converts a character to a key code.
*
* @param {String} character A single character.
* @return {Number} The corresponding key code.
*/
function characterToKeyCode( character ) {
return character.toUpperCase().charCodeAt( 0 );
}

/**
* Check if the access keys and the given character are presssed.
*
Expand All @@ -26,15 +36,11 @@ export const F10 = 121;
* @return {Boolean} True if the combination is pressed, false if not.
*/
export function isAccess( event, character ) {
if ( isMac ) {
if ( ! event.ctrlKey || ! event.altKey ) {
return false;
}
} else if ( ! event.shiftKey || ! event.altKey ) {
if ( ! event[ isMac ? 'ctrlKey' : 'shiftKey' ] || ! event.altKey ) {
return false;
}

return character ? event.keyCode === character.toUpperCase().charCodeAt( 0 ) : true;
return ! character || ( event.keyCode === characterToKeyCode( character ) );
}

/**
Expand Down

0 comments on commit ebac53e

Please sign in to comment.