user414873 user414873 - 5 months ago 69
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.


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

 function onNewLine(e){
    editor.replaceSelection("\n" ,"end");