Search code examples
javascriptcodemirror

Detect new line in codemirror, without overriding default behavior of Enter key


I am trying to detect when the user presses Enter in codemirror. I found this answer: Detecting new line in codemirror

However, when using:

extraKeys:{
    Enter: myFunction
}

It overrides the default behavior of pressing the enter key, which is "newlineAndIndent", meaning there is no new line created at all.

I would like a function to be called when the user presses enter, whilst keeping the default behaviors of the Enter key. I guess I could just have myFunction to add a newline to the editor, but it is called many times for different reasons, so it isn't very appropriate to have it interact with the editor.

Thanks a lot.


Solution

  • Returning CodeMirror.Pass from a key handler will cause the default behavior (or the next keyhandler) to be run after your handler returns.