preventDefault does not work in onPaste

I had a similar problem - in an older version of CodeMirror, it was possible to cancel the paste event, but it appears that the paste functionality has been refactored and this no longer works.

I wouldn’t call undo(), that seems to be a lot of wasted processing if you do that. I would do as marijn suggested - set up a beforeChange listener and cancel the change if it is a paste.