1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 09:13:24 +01:00
slate/lib/utils/key.js

110 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-27 17:16:18 -07:00
import { IS_MAC, IS_WINDOWS } from './environment'
/**
2016-07-07 19:37:34 -07:00
* Does an `e` have the alt modifier?
2016-06-27 17:16:18 -07:00
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isAlt(e) {
return e.altKey
}
/**
* Does an `e` have the command modifier?
*
* @param {Event} e
* @return {Boolean}
*/
function isCommand(e) {
2016-06-27 17:16:18 -07:00
return IS_MAC
2016-07-07 19:37:34 -07:00
? e.metaKey && !e.altKey
: e.ctrlKey && !e.altKey
2016-06-27 17:16:18 -07:00
}
/**
* Does an `e` have the control modifier?
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isCtrl(e) {
2016-06-27 17:16:18 -07:00
return e.ctrlKey && !e.altKey
}
2016-07-07 19:37:34 -07:00
/**
* Does an `e` have the Mac command modifier?
*
* @param {Event} e
* @return {Boolean}
*/
function isMacCommand(e) {
return IS_MAC && isCommand(e)
}
2016-06-27 17:16:18 -07:00
/**
* Does an `e` have the option modifier?
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isOption(e) {
2016-06-27 17:16:18 -07:00
return IS_MAC && e.altKey
}
/**
* Does an `e` have the shift modifier?
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isShift(e) {
2016-06-27 17:16:18 -07:00
return e.shiftKey
}
/**
2016-07-07 19:37:34 -07:00
* Does an `e` have the Windows command modifier?
2016-06-27 17:16:18 -07:00
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isWindowsCommand(e) {
return IS_WINDOWS && isCommand(e)
2016-06-27 17:16:18 -07:00
}
/**
2016-07-07 19:37:34 -07:00
* Does an `e` have the word-level modifier?
2016-06-27 17:16:18 -07:00
*
* @param {Event} e
* @return {Boolean}
*/
2016-07-07 19:37:34 -07:00
function isWord(e) {
return IS_MAC
? e.altKey
: e.ctrlKey
2016-06-27 17:16:18 -07:00
}
/**
2016-07-07 19:37:34 -07:00
* Export.
2016-06-27 17:16:18 -07:00
*/
2016-07-07 19:37:34 -07:00
export default {
isAlt,
isCommand,
isCtrl,
isMacCommand,
isOption,
isShift,
isWindowsCommand,
isWord
2016-06-27 17:16:18 -07:00
}