# all files / bpmn-js/lib/features/keyboard/ BpmnKeyboardBindings.js

86.54% Statements 45/52
73.33% Branches 22/30
100% Functions 10/10
86.54% Lines 45/52

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158

    66×

    1×

    1×

    1×

    66×

    462×
    462×

    66×

    12×

    12×
    2×

    2×

    66×

    10×

    10×
    2×

    2×

    66×

    8×

    8×

    8×
    2×

    2×

    66×

    6×

    6×

    6×
    2×

    2×

    66×

    4×

    4×

    4×

    66×

    4×

    4×

    4×
    2×

    2×

    66×

    2×

    2×

    2×
    2×

    2×

     import inherits from 'inherits';

    import KeyboardBindings from 'diagram-js/lib/features/keyboard/KeyboardBindings';

    /**
     * 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) {

        Eif (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;

        Iif (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;

        Iif (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;

        Iif (keyboard.hasModifier(event)) {
          return;
        }

        Iif (keyboard.isKey(['h', 'H'], event)) {
          editorActions.trigger('handTool');

          return true;
        }
      });

      // activate global connect tool
      // C
      addListener('globalConnectTool', function(context) {

        var event = context.keyEvent;

        Iif (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;

        Iif (keyboard.hasModifier(event)) {
          return;
        }

        Eif (keyboard.isKey(['e', 'E'], event)) {
          editorActions.trigger('directEditing');

          return true;
        }
      });

    };