reorganization of shortcuts in the options

This commit is contained in:
zadam
2019-11-24 10:40:18 +01:00
parent 1f37d00e42
commit c400a7143c
8 changed files with 223 additions and 181 deletions

View File

@@ -33,7 +33,7 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
}
});
function setActionHandler(actionName, handler) {
function setGlobalActionHandler(actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];
@@ -51,6 +51,24 @@ function setActionHandler(actionName, handler) {
});
}
function setElementActionHandler($el, actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];
if (!action) {
throw new Error(`Cannot find keyboard action '${actionName}'`);
}
// not setting action.handler since this is not global
for (const shortcut of action.effectiveShortcuts) {
if (shortcut) {
utils.bindElShortcut($el, shortcut, handler);
}
}
});
}
async function triggerAction(actionName) {
const action = getAction(actionName);
@@ -105,7 +123,8 @@ function updateDisplayedShortcuts($container) {
$(() => updateDisplayedShortcuts($(document)));
export default {
setActionHandler,
setGlobalActionHandler,
setElementActionHandler,
triggerAction,
getAction,
updateDisplayedShortcuts