Key Bindings
This plugin will be responsible handling the key presses, it will be receiving the getKeys
function from the different plugins that handle keys behaviours.
First thing to be done is getting all the plugins, we use the getPlugins function for that purpose, then we iterate between them.
const keyBindingFn = (e, obj) => {
const allPlugins = obj.getPlugins();
let returnable = getDefaultKeyBinding(e);
allPlugins.map((plugin) => {
//Check if the plugin has the getKeys() function
});
return returnable;
};
Inside the iteration, we check if the current plugin has the getKeys function and if exist, we execute it and check if the keys are pressed, returning our custom keyWord, or returning the default keybinding, if not.
if (plugin.getKeys) {
const Keys = plugin.getKeys();
if (e.keyCode === Keys.keyCode && Keys.hasCommandModifier === hasCommandModifier(e)
&& e.altKey === Keys.altKey) {
returnable = Keys.keyWord;
}
}