I’ve got a CodeMirror instance (currently using fromTextArea). On page load, a file is loaded into the relevant textarea. In some situations, that file can be quite large and takes a while to fully load. This results in the textarea being displayed for several seconds before CodeMirror takes over. Is there a way to dynamically load the file? Or display a preloader of some sort?
You can use the usual DOM techniques to display a loading icon, but that’s not something CodeMirror will help you with. What might also work is instantiating the
Doc instance first (which is probably th expensive part), and then creating an editor with that doc as content. That’s still syncronous, though. You could, if you really have huge content, even try to make it async by building up the doc chunk by chunk, using
replaceRange to push, say, 1000-line blobs into it, and then backing off for a few milliseconds using
setTimeout, so that the UI can respond again.