I'm trying to do all of the following things, at the same HTML page:
- Put more than one ACE editor in the same page
- There will be no need to define each editor its own ID tags
- There will be no need to define each editor its own HEIGHT
- The height of each editor will automatically initialized according to its default text
- The height of each editor will automatically grow when adding it text and reduced automatically when deleting from it text
I used this code: https://stackoverflow.com/a/27114508/5354360 for 1. and 2.
I used this code: https://stackoverflow.com/a/13579233/5354360 for 3. 4. 5.
Each of the codes works great by itself, but when I try to combine them and create more than one editor in the same page, the height set according to the last editor.
How should I fix the code?
Thanks!
my code:
<script type = "text/javascript" src = "http://code.jquery.com/jquery.min.js"></script>
<script src = "https://ace.c9.io/build/src/ace.js" type = "text/javascript" charset = "utf-8"></script>
<script>
$(document).ready(function()
{
$('.ace_editor').each(function()
{
var editor = ace.edit(this);
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/c_cpp");
var heightUpdateFunction = function()
{
var newHeight = editor.getSession().getScreenLength() * editor.renderer.lineHeight;
editor.setOptions({ maxLines: Infinity });
editor.resize();
};
heightUpdateFunction();
editor.getSession().on('change', heightUpdateFunction);
});
});
</script>
<pre class = "ace_editor" style = "width:50%;">
#include < iostream >
usimg namespcse std;
int main ()
{
for (int i = 0; i < 10; i++)
printf ("%d", i);
return 0;
}
</pre>
<br>
<pre class = "ace_editor" style = "width:50%;">
for (int i = 0; i < 10; i++)
printf ("%d", i);
}
</pre>