Skip to content Skip to sidebar Skip to footer

Codemirror Has Content But Won't Display Until Keypress

I have a CodeMirror instance embedded in a webapp I'm building. It works great - except that the initial content won't display until user enters a new character. So it is all there

Solution 1:

You do indeed need to call a refresh() on your CodeMirror instance if this is happening. But due to space monkeys you'll need to wrap the refresh call in a timeout:

var editor = CodeMirror.fromTextArea( yourSourceDOM, { lineNumbers:true })
setTimeout( editor.refresh, 0 )

It's not pretty, but that solved it for me.

Solution 2:

Using code mirror 5.14.2, if you refresh explicitly you must take care to invoke it properly (see this question) but it is most easily handled with the codemirror supplied autorefresh add on.

Solution 3:

If you're using CodeMirror version 2+, you can call CodeMirror.refresh(). See the documentation on refresh().

Note: This must be called on the CodeMirror instance and not the element. See https://stackoverflow.com/a/5377029/526741

Post a Comment for "Codemirror Has Content But Won't Display Until Keypress"