bpmn-js/lib/features/keyboard/BpmnKeyBindings.js

83 lines
1.7 KiB
JavaScript

'use strict';
function BpmnKeyBindings(keyboard, spaceTool, lassoTool, directEditing,
selection, canvas, elementRegistry, editorActions) {
var actions = {
selectElements: function() {
// select all elements except for the invisible
// root element
var rootElement = canvas.getRootElement();
var elements = elementRegistry.filter(function(element) {
return element != rootElement;
});
selection.select(elements);
},
spaceTool: function() {
spaceTool.activateSelection();
},
lassoTool: function() {
lassoTool.activateSelection();
},
directEditing: function() {
var currentSelection = selection.get();
if (currentSelection.length) {
directEditing.activate(currentSelection[0]);
}
}
};
editorActions.register(actions);
keyboard.addListener(function(key, modifiers) {
// ctrl + a -> select all elements
if (key === 65 && keyboard.isCmd(modifiers)) {
editorActions.trigger('selectElements');
return true;
}
if (keyboard.hasModifier(modifiers)) {
return;
}
// s -> activate space tool
if (key === 83) {
editorActions.trigger('spaceTool');
return true;
}
// l -> activate lasso tool
if (key === 76) {
editorActions.trigger('lassoTool');
return true;
}
// e -> activate direct editing
if (key === 69) {
editorActions.trigger('directEditing');
return true;
}
});
}
BpmnKeyBindings.$inject = [
'keyboard',
'spaceTool',
'lassoTool',
'directEditing',
'selection',
'canvas',
'elementRegistry',
'editorActions'
];
module.exports = BpmnKeyBindings;