user414873 user414873 - 1 year ago 167
Javascript Question

CodeMirror: Catching Enter Key prevents line breaks

I used the extraKeys-option of CodeMirror 3.12 to detect when the user starts a new line:

extraKeys: {
"Enter": onNewLine

onNewLine() does nothing but a console.log(). Now CodeMirror ignores that key. You can't start a new line anymore. Is there a way to hook up additional functionality on a new-line-event without interfering CodeMirror internals? I just want to analyze the text of the recently closed line.

Answer Source

Add a line break at the end of onNewLine function. This should work

 function onNewLine(e){
    editor.replaceSelection("\n" ,"end");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download