Search code examples
javascripthtmlcodemirror

Codemirror autoresize upto a given number of lines


I'm trying to allow codemirror to autoresize up to a given number of lines or pixel height. After this max-size is reached the widget should add scrollbars.

CodeMirror.fromTextArea(document.getElementById("code"), {
   lineNumbers: true,
   viewportMargin: 50

});

max-height is not working

.CodeMirror {
 border: 1px solid #eee;
 height: 100%;
}

http://jsfiddle.net/qzjo4ejh/


Solution

  • You should give .CodeMirror a height: auto style, and put the max-height on .CodeMirror-scroll. The embedded editor on the project page does this (view source, it's right near the top).