These [two](https://github.com/jupyter/notebook/blob/master/notebook/static/base/js/utils.js#L492-L528) utils functions seem to exist [in codemirror](https://github.com/codemirror/CodeMirror/blob/master/lib/codemirror.js#L7572-L7590) I guess they are more reliable.