parent
5d5683ff64
commit
03b4a59f84
|
@ -1,16 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function BpmnKeyBindings(
|
function BpmnKeyBindings(keyboard, spaceTool, lassoTool, directEditing,
|
||||||
keyboard, spaceTool, lassoTool,
|
selection, canvas, elementRegistry, editorActions) {
|
||||||
directEditing, selection, canvas,
|
|
||||||
elementRegistry) {
|
|
||||||
|
|
||||||
|
|
||||||
keyboard.addListener(function(key, modifiers) {
|
|
||||||
|
|
||||||
// ctrl + a -> select all elements
|
|
||||||
if (key === 65 && keyboard.isCmd(modifiers)) {
|
|
||||||
|
|
||||||
|
var actions = {
|
||||||
|
selectElements: function() {
|
||||||
// select all elements except for the invisible
|
// select all elements except for the invisible
|
||||||
// root element
|
// root element
|
||||||
var rootElement = canvas.getRootElement();
|
var rootElement = canvas.getRootElement();
|
||||||
|
@ -20,6 +14,29 @@ function BpmnKeyBindings(
|
||||||
});
|
});
|
||||||
|
|
||||||
selection.select(elements);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -30,25 +47,21 @@ function BpmnKeyBindings(
|
||||||
|
|
||||||
// s -> activate space tool
|
// s -> activate space tool
|
||||||
if (key === 83) {
|
if (key === 83) {
|
||||||
spaceTool.activateSelection();
|
editorActions.trigger('spaceTool');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// l -> activate lasso tool
|
// l -> activate lasso tool
|
||||||
if (key === 76) {
|
if (key === 76) {
|
||||||
lassoTool.activateSelection();
|
editorActions.trigger('lassoTool');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentSelection = selection.get();
|
|
||||||
|
|
||||||
// e -> activate direct editing
|
// e -> activate direct editing
|
||||||
if (key === 69) {
|
if (key === 69) {
|
||||||
if (currentSelection.length) {
|
editorActions.trigger('directEditing');
|
||||||
directEditing.activate(currentSelection[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +75,8 @@ BpmnKeyBindings.$inject = [
|
||||||
'directEditing',
|
'directEditing',
|
||||||
'selection',
|
'selection',
|
||||||
'canvas',
|
'canvas',
|
||||||
'elementRegistry'
|
'elementRegistry',
|
||||||
|
'editorActions'
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = BpmnKeyBindings;
|
module.exports = BpmnKeyBindings;
|
||||||
|
|
|
@ -10,7 +10,8 @@ var coreModule = require('../../../../lib/core'),
|
||||||
selectionModule = require('diagram-js/lib/features/selection'),
|
selectionModule = require('diagram-js/lib/features/selection'),
|
||||||
spaceToolModule = require('diagram-js/lib/features/space-tool'),
|
spaceToolModule = require('diagram-js/lib/features/space-tool'),
|
||||||
lassoToolModule = require('diagram-js/lib/features/lasso-tool'),
|
lassoToolModule = require('diagram-js/lib/features/lasso-tool'),
|
||||||
zoomScrollModule = require('diagram-js/lib/navigation/zoomscroll');
|
zoomScrollModule = require('diagram-js/lib/navigation/zoomscroll'),
|
||||||
|
editorActionsModule = require('diagram-js/lib/features/editor-actions');
|
||||||
|
|
||||||
var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent;
|
var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent;
|
||||||
|
|
||||||
|
@ -27,7 +28,8 @@ describe('features - keyboard', function() {
|
||||||
spaceToolModule,
|
spaceToolModule,
|
||||||
lassoToolModule,
|
lassoToolModule,
|
||||||
keyboardModule,
|
keyboardModule,
|
||||||
zoomScrollModule
|
zoomScrollModule,
|
||||||
|
editorActionsModule
|
||||||
];
|
];
|
||||||
|
|
||||||
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
||||||
|
@ -40,6 +42,11 @@ describe('features - keyboard', function() {
|
||||||
container = TestContainer.get(this);
|
container = TestContainer.get(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include triggers inside editorActions', inject(function(editorActions) {
|
||||||
|
// then
|
||||||
|
expect(editorActions.length()).to.equal(10);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should trigger lasso tool', inject(function(keyboard, lassoTool) {
|
it('should trigger lasso tool', inject(function(keyboard, lassoTool) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue