What does Alt Key refer to in Mac for codemirror commands?

Viewed 160

In CodeMirror docs, https://codemirror.net/doc/manual.html#commands, there are some commands that use Alt key in Mac. But Mac does not have an Alt key.

For ex: Alt-B (Mac) is mapped to action goWordLeft.

  1. Does codemirror docs refer to Mac's Option key in shortcuts that use Alt ?
  2. If I want to add a key mapping for Option-[ in Mac (and Alt-[ in windows), how can i do that ?
1 Answers
  1. Probably, if option and alt use the same keycode. I don't use mac so I cannot test it. Here is a list of keycodes.

  2. You can use keydown to detect which keys are down. Create an empty array where we will set our keys that are down. Once a key is down, add it to the keys array, if both keys you want are down, do something. Here is a fiddle

    var keys = {};
    $(document).on('keydown', '.CodeMirror', function(e) {
        var cm = $(this).closest('.codemirror_wrap'); // the editor's wrapper
        var editor = cm[0].editor;

        keys[e.which] = true; // set key[keycode pressed] to true 

        // detect if each key we want is down
        if (keys[18] && keys[219]) {
            // do something
        }
    });

    $(document).keyup(function (e) {
    // remove this key from the keys array
        delete keys[e.which];
    });
Related