Automatically adjust height to contents in Ace Cloud 9 editor

前端 未结 8 1982
孤街浪徒
孤街浪徒 2020-12-04 11:28

I\'m trying to add the Ace editor to a page, but I don\'t know how to get the height to be set automatically based on the length of its contents.

Ideally it would wo

相关标签:
8条回答
  • 2020-12-04 11:55

    Ace provides an option: maxLines so that you can simply try:

    editor.setOptions({
        maxLines: 15
    });
    

    http://jsfiddle.net/cirosantilli/9xdkszbz/

    0 讨论(0)
  • 2020-12-04 12:00

    This variant works better for me as sometimes the editor.renderer.lineHeight returns 1

        var resize = function() {
         var minHt = 16;
         var sl = editor.getSession().getScreenLength();
         var sw = editor.renderer.scrollBar.getWidth();
         var lh = Math.max(editor.renderer.lineHeight, minHt);
         var ht = Math.max(((sl * lh) + sw), minHt);
         $('#myEditorDiv').height(ht);
         editor.resize();
       };
    
    0 讨论(0)
提交回复
热议问题