Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 558
ic3 Avatar asked May 07 '15 10:05

ic3


People also ask

How do you integrate CodeMirror?

Integrating with VuePut the <div> you will attach your CodeMirror to in your Vue template. Create the CodeMirror instance in the mounted lifecycle hook. Use $refs to get a reference to the <div> in the component's template. Listen for changes to your CodeMirror instance by listening to CodeMirror's 'changes' event.

How do I change the height on my CodeMirror?

By setting an editor's height style to auto and giving the viewportMargin a value of Infinity , CodeMirror can be made to automatically resize to fit its content.

How do I use CodeMirror in textarea?

This could be used to, for example, replace a textarea with a real editor: var myCodeMirror = CodeMirror(function(elt) { myTextArea. parentNode. replaceChild(elt, myTextArea); }, {value: myTextArea.

What is CodeMirror plugin?

CodeMirror is a code editor component for the web. It can be used in websites to implement a text input field with support for many editing features, and has a rich programming interface to allow further extension. 9.


1 Answers

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).

like image 152
Marijn Avatar answered Sep 25 '22 18:09

Marijn