feat(keyboard): rewrite listeners to use event passed in context

With the new version of `diagram-js`, the keyboard listeners receive
a single parameter which is an object with `KeyboardEvent` event
as the only property. `BpmnKeyBindings` needed to change in order
to make use of new version of API.
This commit is contained in:
Maciej Barelkowski 2018-10-24 13:31:02 +02:00 committed by merge-me[bot]
parent 03cd2a7e11
commit 75135b667a
1 changed files with 75 additions and 17 deletions

View File

@ -6,61 +6,119 @@
*/
export default function BpmnKeyBindings(keyboard, editorActions) {
keyboard.addListener(function(key, modifiers) {
// ctrl + a -> select all elements
function selectAll(context) {
// ctrl + a -> select all elements
if (key === 65 && keyboard.isCmd(modifiers)) {
var event = context.event;
if (event.keyCode === 65 && keyboard.isCmd(event)) {
editorActions.trigger('selectElements');
return true;
}
}
// ctrl + f -> search labels
if (key === 70 && keyboard.isCmd(modifiers)) {
// ctrl + f -> search labels
function find(context) {
var event = context.event;
if (event.keyCode === 70 && keyboard.isCmd(event)) {
editorActions.trigger('find');
return true;
}
}
if (keyboard.hasModifier(modifiers)) {
// s -> activate space tool
function spaceTool(context) {
var event = context.event;
if (keyboard.hasModifier(event)) {
return;
}
// s -> activate space tool
if (key === 83) {
if (event.keyCode === 83) {
editorActions.trigger('spaceTool');
return true;
}
}
// l -> activate lasso tool
if (key === 76) {
// l -> activate lasso tool
function lassoTool(context) {
var event = context.event;
if (keyboard.hasModifier(event)) {
return;
}
if (event.keyCode === 76) {
editorActions.trigger('lassoTool');
return true;
}
}
// h -> activate hand tool
if (key === 72) {
// h -> activate hand tool
function handTool(context) {
var event = context.event;
if (keyboard.hasModifier(event)) {
return;
}
if (event.keyCode === 72) {
editorActions.trigger('handTool');
return true;
}
}
// c -> activate global connect tool
if (key === 67) {
// c -> activate global connect tool
function globalConnectTool(context) {
var event = context.event;
if (keyboard.hasModifier(event)) {
return;
}
if (event.keyCode === 67) {
editorActions.trigger('globalConnectTool');
return true;
}
}
// e -> activate direct editing
if (key === 69) {
// e -> activate direct editing
function directEditing(context) {
var event = context.event;
if (keyboard.hasModifier(event)) {
return;
}
if (event.keyCode === 69) {
editorActions.trigger('directEditing');
return true;
}
});
}
keyboard.addListener(selectAll);
keyboard.addListener(find);
keyboard.addListener(spaceTool);
keyboard.addListener(lassoTool);
keyboard.addListener(handTool);
keyboard.addListener(globalConnectTool);
keyboard.addListener(directEditing);
}
BpmnKeyBindings.$inject = [