diff --git a/src/libs/KeyboardShortcut/index.js b/src/libs/KeyboardShortcut/index.js index 250fa9c9c3d4..3cc302801e99 100644 --- a/src/libs/KeyboardShortcut/index.js +++ b/src/libs/KeyboardShortcut/index.js @@ -11,43 +11,62 @@ function bindHandlerToKeyupEvent(event) { return; } - // The active callback is the last element in the array const eventCallbacks = events[event.keyCode]; - const callback = eventCallbacks[eventCallbacks.length - 1]; - const pressedModifiers = _.all(callback.modifiers, (modifier) => { - if (modifier === 'shift' && !event.shiftKey) { - return false; - } - if (modifier === 'control' && !event.ctrlKey) { + // Loop over all the callbacks + eventCallbacks.forEach((callback) => { + const pressedModifiers = _.all(callback.modifiers, (modifier) => { + if (modifier === 'shift' && !event.shiftKey) { + return false; + } + if (modifier === 'control' && !event.ctrlKey) { + return false; + } + if (modifier === 'alt' && !event.altKey) { + return false; + } + if (modifier === 'meta' && !event.metaKey) { + return false; + } + return true; + }); + + const extraModifiers = _.difference(['shift', 'control', 'alt', 'meta'], callback.modifiers); + + // returns true if extra modifiers are pressed + const pressedExtraModifiers = _.some(extraModifiers, (extraModifier) => { + if (extraModifier === 'shift' && event.shiftKey) { + return true; + } + if (extraModifier === 'control' && event.ctrlKey) { + return true; + } + if (extraModifier === 'alt' && event.altKey) { + return true; + } + if (extraModifier === 'meta' && event.metaKey) { + return true; + } return false; + }); + if (!pressedModifiers || pressedExtraModifiers) { + return; } - if (modifier === 'alt' && !event.altKey) { - return false; + + // If configured to do so, prevent input text control to trigger this event + if (!callback.captureOnInputs && ( + event.target.nodeName === 'INPUT' + || event.target.nodeName === 'TEXTAREA' + || event.target.contentEditable === 'true' + )) { + return; } - if (modifier === 'meta' && !event.metaKey) { - return false; + + if (_.isFunction(callback.callback)) { + callback.callback(event); } - return true; + event.preventDefault(); }); - - if (!pressedModifiers) { - return; - } - - // If configured to do so, prevent input text control to trigger this event - if (!callback.captureOnInputs && ( - event.target.nodeName === 'INPUT' - || event.target.nodeName === 'TEXTAREA' - || event.target.contentEditable === 'true' - )) { - return; - } - - if (_.isFunction(callback.callback)) { - callback.callback(event); - } - event.preventDefault(); } // Make sure we don't add multiple listeners diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 1d5e0a30376a..ffd10df535c5 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -31,6 +31,7 @@ import {getPolicySummaries, getPolicyList} from '../../actions/Policy'; import modalCardStyleInterpolator from './modalCardStyleInterpolator'; import createCustomModalStackNavigator from './createCustomModalStackNavigator'; import Permissions from '../../Permissions'; +import getOperatingSystem from '../../getOperatingSystem'; // Main drawer navigator import MainDrawerNavigator from './MainDrawerNavigator'; @@ -155,10 +156,24 @@ class AuthScreens extends React.Component { Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); - // Listen for the Command+K key being pressed so the focus can be given to the chat switcher - KeyboardShortcut.subscribe('K', () => { - Navigation.navigate(ROUTES.SEARCH); - }, ['meta'], true); + // Listen for the key K being pressed so that focus can be given to + // the chat switcher, or new group chat + // based on the key modifiers pressed and the operating system + if (getOperatingSystem() === CONST.OS.MAC_OS) { + KeyboardShortcut.subscribe('K', () => { + Navigation.navigate(ROUTES.SEARCH); + }, ['meta'], true); + KeyboardShortcut.subscribe('K', () => { + Navigation.navigate(ROUTES.NEW_GROUP); + }, ['meta', 'shift'], true); + } else { + KeyboardShortcut.subscribe('K', () => { + Navigation.navigate(ROUTES.SEARCH); + }, ['control'], true); + KeyboardShortcut.subscribe('K', () => { + Navigation.navigate(ROUTES.NEW_GROUP); + }, ['control', 'shift'], true); + } } shouldComponentUpdate(nextProps) {