| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import inherits from 'inherits-browser';
- import KeyboardBindings from 'diagram-js/lib/features/keyboard/KeyboardBindings';
- /**
- * @typedef {import('didi').Injector} Injector
- * @typedef {import('diagram-js/lib/features/editor-actions/EditorActions').default} EditorActions
- * @typedef {import('diagram-js/lib/features/keyboard/Keyboard').default} Keyboard
- */
- /**
- * BPMN 2.0 specific keyboard bindings.
- *
- * @param {Injector} injector
- */
- export default function BpmnKeyboardBindings(injector) {
- injector.invoke(KeyboardBindings, this);
- }
- inherits(BpmnKeyboardBindings, KeyboardBindings);
- BpmnKeyboardBindings.$inject = [
- 'injector'
- ];
- /**
- * Register available keyboard bindings.
- *
- * @param {Keyboard} keyboard
- * @param {EditorActions} editorActions
- */
- BpmnKeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
- // inherit default bindings
- KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
- /**
- * Add keyboard binding if respective editor action
- * is registered.
- *
- * @param {string} action name
- * @param {Function} fn that implements the key binding
- */
- function addListener(action, fn) {
- if (editorActions.isRegistered(action)) {
- keyboard.addListener(fn);
- }
- }
- // select all elements
- // CTRL + A
- addListener('selectElements', function(context) {
- var event = context.keyEvent;
- if (keyboard.isKey([ 'a', 'A' ], event) && keyboard.isCmd(event)) {
- editorActions.trigger('selectElements');
- return true;
- }
- });
- // search labels
- // CTRL + F
- addListener('find', function(context) {
- var event = context.keyEvent;
- if (keyboard.isKey([ 'f', 'F' ], event) && keyboard.isCmd(event)) {
- editorActions.trigger('find');
- return true;
- }
- });
- // activate space tool
- // S
- addListener('spaceTool', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 's', 'S' ], event)) {
- editorActions.trigger('spaceTool');
- return true;
- }
- });
- // activate lasso tool
- // L
- addListener('lassoTool', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 'l', 'L' ], event)) {
- editorActions.trigger('lassoTool');
- return true;
- }
- });
- // activate hand tool
- // H
- addListener('handTool', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 'h', 'H' ], event)) {
- editorActions.trigger('handTool');
- return true;
- }
- });
- // activate global connect tool
- // C
- addListener('globalConnectTool', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 'c', 'C' ], event)) {
- editorActions.trigger('globalConnectTool');
- return true;
- }
- });
- // activate direct editing
- // E
- addListener('directEditing', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 'e', 'E' ], event)) {
- editorActions.trigger('directEditing');
- return true;
- }
- });
- // activate replace element
- // R
- addListener('replaceElement', function(context) {
- var event = context.keyEvent;
- if (keyboard.hasModifier(event)) {
- return;
- }
- if (keyboard.isKey([ 'r', 'R' ], event)) {
- editorActions.trigger('replaceElement', event);
- return true;
- }
- });
- };
|