Replace range directly in CodeMirror instance insted of using the document.

This fixes issue #2775.