Search code examples
javascriptjquerycodemirrorkeycode

What is the keycode for the open curly brace {


I'm creating a code-mirror instance with an autocomplete system that will activate on any key press. But whenever you type: { the auto complete still appears even though there is an if statement blocking key code 219 from showing the autocomplete. The reason why I want to stop the { from opening the autocomplete menu is that the user would usually press Enter to go down a line but it puts in the suggestion from the autocomplete. I've already tried using charCode but that didn't work.

here is my code:

editor.on("keyup", function (cm, event) {
            if (!cm.state.completionActive && event.keyCode != 13 && event.keyCode != 219) { 
                CodeMirror.commands.autocomplete(cm, null, {completeSingle: false});
            }
        });

I want it to not open the autocomplete menu in codemirror whenever the user presses {


Solution

  • I figured it out by replacing keyCode with charCode and changing the event to keypress.

    editor.on("keypress", function (cm, event) {
                if (!cm.state.completionActive && event.charCode != 13 && event.charCode != 123) {
                    CodeMirror.commands.autocomplete(cm, null, {completeSingle: false});
                }
            });