editor.panes.codeMirror gets accessed a lot here and the next clause. Cache this before the if/else block in a separate var?