Search code examples
google-chromecodemirror

CodeMirror does not prevent Ctrl+T to open a new tab


I'm currently using CodeMirror and here is the code I have:

    cm.setOption("extraKeys", {
        'Ctrl-T':  function() {
            insertTitle();
            return false;
        }
    });

The main idea is to execute the function insertTitle when the user presses Ctrl+T.

The issue is that, instead of executing this function, Chrome opens a new tab (default behaviour).

I tried to replace Ctrl-T by Ctrl-A but it didn't work.

I also tried with or without return false but it does not change anything.

Is there a way to prevent the Chrome default behavior ?


Solution

  • Chrome does not allow scripts to capture some keys. Ctrl-T appears to be one of them (Ctrl-N and Ctrl-W are others). There's nothing CodeMirror can do about this.