mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
* WIP * WIP * Wip * Wip * wip * Refactor without normalize and plugin * Replace extendKeymaps by decorateKeymaps * WIP * Add mousetrap * Add first command over rpc * More commands * Add all commands * Begin to hook commands * Working multiple keymaps * Use redux action to trigger command * Use forked version of Mousetrap to capture key events * Fix lint * Add command in redux action to debug purpose * ExecCommand from menu click * Remove unused files * Fix xterm should ignore catched events * Re-enable IntelliSense checking * Remove unused runes dep
46 lines
1 KiB
JavaScript
46 lines
1 KiB
JavaScript
import {remote} from 'electron';
|
|
|
|
const {getDecoratedKeymaps} = remote.require('./plugins');
|
|
|
|
let commands = {};
|
|
|
|
export const getRegisteredKeys = () => {
|
|
const keymaps = getDecoratedKeymaps();
|
|
|
|
return Object.keys(keymaps).reduce((result, actionName) => {
|
|
const commandKeys = keymaps[actionName];
|
|
commandKeys.forEach(shortcut => {
|
|
result[shortcut] = actionName;
|
|
});
|
|
return result;
|
|
}, {});
|
|
};
|
|
|
|
export const registerCommandHandlers = cmds => {
|
|
if (!cmds) {
|
|
return;
|
|
}
|
|
|
|
commands = Object.assign(commands, cmds);
|
|
};
|
|
|
|
export const getCommandHandler = command => {
|
|
return commands[command];
|
|
};
|
|
|
|
// Some commands are firectly excuted by Electron menuItem role.
|
|
// They should not be prevented to reach Electron.
|
|
const roleCommands = [
|
|
'window:close',
|
|
'editor:undo',
|
|
'editor:redo',
|
|
'editor:cut',
|
|
'editor:copy',
|
|
'editor:paste',
|
|
'editor:selectAll',
|
|
'window:minimize',
|
|
'window:zoom',
|
|
'window:toggleFullScreen'
|
|
];
|
|
|
|
export const shouldPreventDefault = command => !roleCommands.includes(command);
|