Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  191] [ 4]  / answers: 1 / hits: 36816  / 13 Years ago, thu, december 1, 2011, 12:00:00

I am using codemirror 2 and its working fine except that the editor's set value doesn't load into the editor until I click the editor and it becomes focused.



I want the editor to show the content of itself without it having to be clicked. Any ideas?



All of the codemirror demos work as expected so I figured maybe the textarea isn't focused so I tried that too.



$(#editor).focus();
var editor = CodeMirror.fromTextArea(document.getElementById(editor), {
mode: text/html,
height: 197px,
lineNumbers: true
});

More From » jquery

 Answers
7

You must call refresh() after setValue(). However, you must use setTimeout to postpone the refresh() to after CodeMirror/Browser has updated the layout according to the new content:



codeMirrorRef.setValue(content);
setTimeout(function() {
codeMirrorRef.refresh();
},1);


It works well for me. I found the answer in here.


[#88795] Wednesday, November 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
osvaldo

Total Points: 102
Total Questions: 95
Total Answers: 102

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;