2017-09-17 14:04:56 +00:00
|
|
|
|
// @flow
|
2019-02-08 18:20:24 +00:00
|
|
|
|
import { keyboardKeys } from './keyboard-keys';
|
|
|
|
|
import { ALT_SYM, CTRL_SYM, isMac, META_SYM, SHIFT_SYM } from './constants';
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* The readable definition of a hotkey.
|
|
|
|
|
* The {@code id} the hotkey's reference id.
|
|
|
|
|
*/
|
|
|
|
|
export type HotKeyDefinition = {
|
|
|
|
|
id: string,
|
2017-09-17 14:04:56 +00:00
|
|
|
|
description: string,
|
2019-03-12 16:38:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The combination of key presses that will activate a hotkey if pressed.
|
|
|
|
|
*/
|
|
|
|
|
export type KeyCombination = {
|
|
|
|
|
ctrl: boolean,
|
2017-09-17 14:04:56 +00:00
|
|
|
|
alt: boolean,
|
|
|
|
|
shift: boolean,
|
2019-03-12 16:38:30 +00:00
|
|
|
|
meta: boolean,
|
|
|
|
|
keyCode: number,
|
2017-09-17 14:04:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* The collection of a hotkey's key combinations for each platforms.
|
|
|
|
|
*/
|
|
|
|
|
export type KeyBindings = {
|
|
|
|
|
macKeys: Array<KeyCombination>,
|
|
|
|
|
// The key combinations for both Windows and Linux.
|
|
|
|
|
winLinuxKeys: Array<KeyCombination>,
|
2017-09-17 14:04:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* The collection of defined hotkeys.
|
|
|
|
|
* The registry maps a hotkey by its reference id to its key bindings.
|
|
|
|
|
*/
|
|
|
|
|
export type HotKeyRegistry = {
|
|
|
|
|
[refId: string]: KeyBindings,
|
2017-09-17 14:04:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
function defineHotKey(id: string, description: string): HotKeyDefinition {
|
|
|
|
|
return {
|
|
|
|
|
id: id,
|
|
|
|
|
description: description,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-12-11 23:11:54 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
function keyComb(
|
|
|
|
|
ctrl: boolean,
|
|
|
|
|
alt: boolean,
|
|
|
|
|
shift: boolean,
|
|
|
|
|
meta: boolean,
|
|
|
|
|
keyCode: number,
|
|
|
|
|
): KeyCombination {
|
|
|
|
|
return {
|
|
|
|
|
ctrl: ctrl,
|
|
|
|
|
alt: alt,
|
|
|
|
|
shift: shift,
|
|
|
|
|
meta: meta,
|
|
|
|
|
keyCode: keyCode,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
function keyBinds(
|
|
|
|
|
mac: KeyCombination | Array<KeyCombination>,
|
|
|
|
|
winLinux: KeyCombination | Array<KeyCombination>,
|
|
|
|
|
): KeyBindings {
|
|
|
|
|
if (!Array.isArray(mac)) {
|
|
|
|
|
mac = [mac];
|
|
|
|
|
}
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
if (!Array.isArray(winLinux)) {
|
|
|
|
|
winLinux = [winLinux];
|
|
|
|
|
}
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
return {
|
|
|
|
|
macKeys: mac,
|
|
|
|
|
winLinuxKeys: winLinux,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* The collection of available hotkeys' and their definitions.
|
|
|
|
|
*/
|
|
|
|
|
// Not using dot, because NeDB prohibits field names to contain dots.
|
|
|
|
|
export const hotKeyRefs = {
|
|
|
|
|
WORKSPACE_SHOW_SETTINGS: defineHotKey('workspace_showSettings', 'Show Workspace Settings'),
|
2017-11-10 14:13:03 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_SETTINGS: defineHotKey('request_showSettings', 'Show Request Settings'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
PREFERENCES_SHOW_KEYBOARD_SHORTCUTS: defineHotKey(
|
|
|
|
|
'preferences_showKeyboardShortcuts',
|
|
|
|
|
'Show Keyboard Shortcuts',
|
|
|
|
|
),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
PREFERENCES_SHOW_GENERAL: defineHotKey('preferences_showGeneral', 'Show App Preferences'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
TOGGLE_MAIN_MENU: defineHotKey('toggleMainMenu', 'Toggle Main Menu'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_QUICK_SWITCH: defineHotKey('request_quickSwitch', 'Switch Requests'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-05-10 01:18:34 +00:00
|
|
|
|
SHOW_RECENT_REQUESTS: defineHotKey('request_showRecent', 'Show Recent Requests'),
|
|
|
|
|
|
|
|
|
|
SHOW_RECENT_REQUESTS_PREVIOUS: defineHotKey(
|
|
|
|
|
'request_showRecentPrevious',
|
|
|
|
|
'Show Recent Requests (Previous)',
|
|
|
|
|
),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
PLUGIN_RELOAD: defineHotKey('plugin_reload', 'Reload Plugins'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
SHOW_AUTOCOMPLETE: defineHotKey('showAutocomplete', 'Show Autocomplete'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SEND: defineHotKey('request_send', 'Send Request'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_OPTIONS: defineHotKey('request_showOptions', 'Send Request (Options)'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
ENVIRONMENT_SHOW_EDITOR: defineHotKey('environment_showEditor', 'Show Environment Editor'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
ENVIRONMENT_SHOW_SWITCH_MENU: defineHotKey('environment_showSwitchMenu', 'Switch Environments'),
|
2018-11-30 05:52:07 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_TOGGLE_HTTP_METHOD_MENU: defineHotKey(
|
|
|
|
|
'request_toggleHttpMethodMenu',
|
|
|
|
|
'Change HTTP Method',
|
|
|
|
|
),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_TOGGLE_HISTORY: defineHotKey('request_toggleHistory', 'Show Request History'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_FOCUS_URL: defineHotKey('request_focusUrl', 'Focus URL'),
|
2017-11-10 14:13:03 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_GENERATE_CODE_EDITOR: defineHotKey(
|
|
|
|
|
'request_showGenerateCodeEditor',
|
|
|
|
|
'Generate Code',
|
|
|
|
|
),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
SIDEBAR_FOCUS_FILTER: defineHotKey('sidebar_focusFilter', 'Filter Sidebar'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-12-14 04:11:13 +00:00
|
|
|
|
SIDEBAR_TOGGLE: defineHotKey('sidebar_toggle', 'Toggle Sidebar'),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
RESPONSE_FOCUS: defineHotKey('response_focus', 'Focus Response'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
SHOW_COOKIES_EDITOR: defineHotKey('showCookiesEditor', 'Edit Cookies'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_CREATE: defineHotKey('request_showCreate', 'Create Request'),
|
2018-11-30 05:50:30 +00:00
|
|
|
|
|
2019-04-26 20:58:05 +00:00
|
|
|
|
REQUEST_QUICK_CREATE: defineHotKey('request_quickCreate', 'Create Request (Quick)'),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_DELETE: defineHotKey('request_showDelete', 'Delete Request'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_CREATE_FOLDER: defineHotKey('request_showCreateFolder', 'Create Folder'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
REQUEST_SHOW_DUPLICATE: defineHotKey('request_showDuplicate', 'Duplicate Request'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-05-07 14:46:35 +00:00
|
|
|
|
REQUEST_TOGGLE_PIN: defineHotKey('request_togglePin', 'Pin/Unpin Request'),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
CLOSE_DROPDOWN: defineHotKey('closeDropdown', 'Close Dropdown'),
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
CLOSE_MODAL: defineHotKey('closeModal', 'Close Modal'),
|
|
|
|
|
|
|
|
|
|
ENVIRONMENT_UNCOVER_VARIABLES: defineHotKey('environment_uncoverVariables', 'Uncover Variables'),
|
|
|
|
|
};
|
2017-09-17 14:04:56 +00:00
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* The default key bindings values of all available hotkeys.
|
|
|
|
|
*/
|
|
|
|
|
const defaultRegistry: HotKeyRegistry = {
|
|
|
|
|
[hotKeyRefs.WORKSPACE_SHOW_SETTINGS.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.comma.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.comma.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_SETTINGS.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, true, true, true, keyboardKeys.comma.keyCode),
|
|
|
|
|
keyComb(true, true, true, false, keyboardKeys.comma.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.PREFERENCES_SHOW_KEYBOARD_SHORTCUTS.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.forwardslash.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.forwardslash.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.PREFERENCES_SHOW_GENERAL.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.comma.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.comma.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.TOGGLE_MAIN_MENU.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, true, false, true, keyboardKeys.comma.keyCode),
|
|
|
|
|
keyComb(true, true, false, false, keyboardKeys.comma.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_QUICK_SWITCH.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.p.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.p.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
2019-05-10 01:18:34 +00:00
|
|
|
|
[hotKeyRefs.SHOW_RECENT_REQUESTS.id]: keyBinds(
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.tab.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.tab.keyCode),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.SHOW_RECENT_REQUESTS_PREVIOUS.id]: keyBinds(
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.tab.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.tab.keyCode),
|
|
|
|
|
),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
[hotKeyRefs.PLUGIN_RELOAD.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.r.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.r.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.SHOW_AUTOCOMPLETE.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.space.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.space.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SEND.id]: keyBinds(
|
|
|
|
|
[
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.enter.keyCode),
|
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.r.keyCode),
|
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.f5.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.enter.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.r.keyCode),
|
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.f5.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_OPTIONS.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.enter.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.enter.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.ENVIRONMENT_SHOW_EDITOR.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.e.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.e.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.ENVIRONMENT_SHOW_SWITCH_MENU.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.e.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.e.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_TOGGLE_HTTP_METHOD_MENU.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.l.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.l.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_TOGGLE_HISTORY.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.h.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.h.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_FOCUS_URL.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.l.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.l.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_GENERATE_CODE_EDITOR.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.g.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.g.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.SIDEBAR_FOCUS_FILTER.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.f.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.f.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
2019-12-14 04:11:13 +00:00
|
|
|
|
[hotKeyRefs.SIDEBAR_TOGGLE.id]: keyBinds(
|
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.backslash.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.backslash.keyCode),
|
|
|
|
|
),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
[hotKeyRefs.RESPONSE_FOCUS.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.singlequote.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.singlequote.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.SHOW_COOKIES_EDITOR.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.k.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.k.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_CREATE.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.n.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.n.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
2019-04-26 20:58:05 +00:00
|
|
|
|
[hotKeyRefs.REQUEST_QUICK_CREATE.id]: keyBinds(
|
|
|
|
|
keyComb(false, true, false, true, keyboardKeys.n.keyCode),
|
|
|
|
|
keyComb(true, true, false, false, keyboardKeys.n.keyCode),
|
|
|
|
|
),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_DELETE.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.delete.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.delete.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_CREATE_FOLDER.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.n.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.n.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.REQUEST_SHOW_DUPLICATE.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, true, keyboardKeys.d.keyCode),
|
|
|
|
|
keyComb(true, false, false, false, keyboardKeys.d.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
2019-05-07 14:46:35 +00:00
|
|
|
|
[hotKeyRefs.REQUEST_TOGGLE_PIN.id]: keyBinds(
|
|
|
|
|
keyComb(false, false, true, true, keyboardKeys.p.keyCode),
|
|
|
|
|
keyComb(true, false, true, false, keyboardKeys.p.keyCode),
|
|
|
|
|
),
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
[hotKeyRefs.CLOSE_DROPDOWN.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.esc.keyCode),
|
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.esc.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.CLOSE_MODAL.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.esc.keyCode),
|
|
|
|
|
keyComb(false, false, false, false, keyboardKeys.esc.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
[hotKeyRefs.ENVIRONMENT_UNCOVER_VARIABLES.id]: keyBinds(
|
2019-02-08 18:20:24 +00:00
|
|
|
|
keyComb(false, true, true, false, keyboardKeys.u.keyCode),
|
|
|
|
|
keyComb(false, true, true, false, keyboardKeys.u.keyCode),
|
2019-03-12 16:38:30 +00:00
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function copyKeyCombs(sources: Array<KeyCombination>): Array<KeyCombination> {
|
|
|
|
|
let targets: Array<KeyCombination> = [];
|
|
|
|
|
sources.forEach(keyComb => {
|
|
|
|
|
targets.push(Object.assign({}, keyComb));
|
|
|
|
|
});
|
|
|
|
|
return targets;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 18:20:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a new copy of key bindings with default key combinations.
|
|
|
|
|
* @param hotKeyRefId
|
|
|
|
|
* @returns {KeyBindings}
|
|
|
|
|
*/
|
|
|
|
|
export function newDefaultKeyBindings(hotKeyRefId: string): KeyBindings {
|
|
|
|
|
const keyBindings: KeyBindings = defaultRegistry[hotKeyRefId];
|
|
|
|
|
return {
|
|
|
|
|
macKeys: copyKeyCombs(keyBindings.macKeys),
|
|
|
|
|
winLinuxKeys: copyKeyCombs(keyBindings.winLinuxKeys),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a new copy of hotkey registry with default values.
|
|
|
|
|
* @returns {HotKeyRegistry}
|
|
|
|
|
*/
|
|
|
|
|
export function newDefaultRegistry(): HotKeyRegistry {
|
|
|
|
|
let newDefaults: HotKeyRegistry = {};
|
|
|
|
|
for (const refId in defaultRegistry) {
|
|
|
|
|
if (!defaultRegistry.hasOwnProperty(refId)) {
|
2017-09-17 14:04:56 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-02-08 18:20:24 +00:00
|
|
|
|
newDefaults[refId] = newDefaultKeyBindings(refId);
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
2019-03-12 16:38:30 +00:00
|
|
|
|
return newDefaults;
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the key combinations based on the current platform.
|
|
|
|
|
* @param bindings
|
|
|
|
|
* @returns {Array<KeyCombination>}
|
|
|
|
|
*/
|
|
|
|
|
export function getPlatformKeyCombinations(bindings: KeyBindings): Array<KeyCombination> {
|
|
|
|
|
if (isMac()) {
|
|
|
|
|
return bindings.macKeys;
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
2019-03-12 16:38:30 +00:00
|
|
|
|
return bindings.winLinuxKeys;
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 18:20:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* Determine whether two key combinations are the same by comparing each of their keys.
|
|
|
|
|
* @param keyComb1
|
|
|
|
|
* @param keyComb2
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
export function areSameKeyCombinations(
|
|
|
|
|
keyComb1: KeyCombination,
|
|
|
|
|
keyComb2: KeyCombination,
|
|
|
|
|
): boolean {
|
|
|
|
|
return (
|
|
|
|
|
keyComb1.alt === keyComb2.alt &&
|
|
|
|
|
keyComb1.shift === keyComb2.shift &&
|
|
|
|
|
keyComb1.ctrl === keyComb2.ctrl &&
|
|
|
|
|
keyComb1.meta === keyComb2.meta &&
|
|
|
|
|
keyComb1.keyCode === keyComb2.keyCode
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the given key bindings is the same as the default one,
|
|
|
|
|
* identified with hot key reference id.
|
|
|
|
|
* @param hotKeyRefId refers to the default key bindings to check.
|
|
|
|
|
* @param keyBinds to check with the default ones.
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
export function areKeyBindingsSameAsDefault(hotKeyRefId: string, keyBinds: KeyBindings): boolean {
|
|
|
|
|
const keyCombs = getPlatformKeyCombinations(keyBinds);
|
|
|
|
|
const defaultKeyCombs = getPlatformKeyCombinations(defaultRegistry[hotKeyRefId]);
|
|
|
|
|
if (keyCombs.length !== defaultKeyCombs.length) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (const keyComb of keyCombs) {
|
|
|
|
|
const found = defaultKeyCombs.find(defKeyComb => {
|
|
|
|
|
if (areSameKeyCombinations(keyComb, defKeyComb)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (found == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the displayed text of a key code.
|
|
|
|
|
* @param keyCode
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
export function getChar(keyCode: number): string {
|
|
|
|
|
let char;
|
2019-02-08 18:20:24 +00:00
|
|
|
|
const key = Object.keys(keyboardKeys).find(k => keyboardKeys[k].keyCode === keyCode);
|
2019-03-12 16:38:30 +00:00
|
|
|
|
|
2019-02-08 18:20:24 +00:00
|
|
|
|
if (!key) {
|
2019-03-12 16:38:30 +00:00
|
|
|
|
console.error('Invalid key code', keyCode);
|
|
|
|
|
} else {
|
2019-02-08 18:20:24 +00:00
|
|
|
|
char = keyboardKeys[key].label;
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 16:38:30 +00:00
|
|
|
|
return char || 'unknown';
|
2017-09-17 14:04:56 +00:00
|
|
|
|
}
|
2019-02-08 18:20:24 +00:00
|
|
|
|
|
|
|
|
|
function joinHotKeys(mustUsePlus: boolean, keys: Array<string>): string {
|
|
|
|
|
if (!mustUsePlus && isMac()) {
|
|
|
|
|
return keys.join('');
|
|
|
|
|
}
|
|
|
|
|
return keys.join('+');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether key code is a modifier key, i.e., alt, shift, ctrl, or meta.
|
|
|
|
|
* @param keyCode
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
export function isModifierKeyCode(keyCode: number): boolean {
|
|
|
|
|
return (
|
|
|
|
|
keyCode === keyboardKeys.alt.keyCode ||
|
|
|
|
|
keyCode === keyboardKeys.shift.keyCode ||
|
|
|
|
|
keyCode === keyboardKeys.ctrl.keyCode ||
|
|
|
|
|
// Meta keys.
|
|
|
|
|
keyCode === keyboardKeys.leftwindowkey.keyCode ||
|
|
|
|
|
keyCode === keyboardKeys.rightwindowkey.keyCode ||
|
|
|
|
|
keyCode === keyboardKeys.selectkey.keyCode
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct the display string of a key combination based on platform.
|
|
|
|
|
* For example, the display of alt in Windows or Linux would be "Alt";
|
|
|
|
|
* while in Mac would be "⌥".
|
|
|
|
|
* @param keyComb
|
|
|
|
|
* @param mustUsePlus if true will join the characters with "+" for all platforms;
|
|
|
|
|
* otherwise if the platform is Mac, the characters will be next to each other.
|
|
|
|
|
* @returns the constructed string, if keyCode is null and the characters are joint with "+",
|
|
|
|
|
* it will have a dangling "+" as the last character, e.g., "Alt+Ctrl+".
|
|
|
|
|
*/
|
|
|
|
|
export function constructKeyCombinationDisplay(
|
|
|
|
|
keyComb: KeyCombination,
|
|
|
|
|
mustUsePlus: boolean,
|
|
|
|
|
): string {
|
|
|
|
|
const { ctrl, alt, shift, meta, keyCode } = keyComb;
|
|
|
|
|
const chars = [];
|
|
|
|
|
|
|
|
|
|
alt && chars.push(ALT_SYM);
|
|
|
|
|
shift && chars.push(SHIFT_SYM);
|
|
|
|
|
ctrl && chars.push(CTRL_SYM);
|
|
|
|
|
meta && chars.push(META_SYM);
|
|
|
|
|
if (keyCode != null && !isModifierKeyCode(keyCode)) {
|
|
|
|
|
chars.push(getChar(keyCode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let joint = joinHotKeys(mustUsePlus, chars);
|
|
|
|
|
if (mustUsePlus && isModifierKeyCode(keyCode)) {
|
|
|
|
|
joint += '+';
|
|
|
|
|
}
|
|
|
|
|
return joint;
|
|
|
|
|
}
|
2019-08-21 00:24:18 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct the display string for a key combination
|
|
|
|
|
*
|
|
|
|
|
* @param hotKeyDef
|
|
|
|
|
* @param hotKeyRegistry
|
|
|
|
|
* @param mustUsePlus
|
|
|
|
|
* @returns {string} – key combination as string or empty string if not found
|
|
|
|
|
*/
|
|
|
|
|
export function getHotKeyDisplay(
|
|
|
|
|
hotKeyDef: HotKeyDefinition,
|
|
|
|
|
hotKeyRegistry: HotKeyRegistry,
|
|
|
|
|
mustUsePlus: boolean,
|
|
|
|
|
) {
|
|
|
|
|
const hotKey: ?KeyBindings = hotKeyRegistry[hotKeyDef.id];
|
|
|
|
|
if (!hotKey) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const keyCombs: Array<KeyCombination> = getPlatformKeyCombinations(hotKey);
|
|
|
|
|
if (keyCombs.length === 0) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return constructKeyCombinationDisplay(keyCombs[0], mustUsePlus);
|
|
|
|
|
}
|