Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codemirror, how to add add-ons

I am trying to add the scroll past end add-on for codemirror but I cannot add it to my codemirror instance.

I tried calling it like this scrollPastEnd: true in the options but that didn't work. I also tried using the defineOption function but the console says it is undefined.

Thanks for the help

like image 829
Corentin Caer Avatar asked Oct 22 '16 05:10

Corentin Caer


People also ask

How do I use CodeMirror addons?

First, you have to add the scrollpastend. js file (https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/addon/scroll/scrollpastend.min.js) to your HTML document and not to the editor. As the following code from scrollpastend.

Does GitHub use CodeMirror?

About. CodeMirror is open source under a permissive license (MIT). It is being developed on GitHub. Contributions are welcome.


1 Answers

First, you have to add the scrollpastend.js file (https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/addon/scroll/scrollpastend.min.js) to your HTML document and not to the editor.

As the following code from scrollpastend.js file says, the scrollPastEnd option is off by default:

CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {..});

Then It only remains to activate your add-on by setting new option like this:

editor.setOption("scrollPastEnd", true);

or adding scrollPastEnd option to the object option list:

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  mode: "html",
  lineNumbers: true,
  scrollPastEnd: true
});

Hoping to help you, I wish you a good day.

like image 66
José dB. Avatar answered Oct 13 '22 01:10

José dB.