Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:43:54+00:00 2026-06-15T01:43:54+00:00

I’m trying to add the Ace editor to a page, but I don’t know

  • 0

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 work so when the content changes the height is recalculated, but I would be happy with the height just being set on page load.

For a JavaScript novice can someone help me figure out how I work out the length of the code, how many lines it spans, what the new height is and how I update the DOM to reflect this?

I found this suggestion in a Google group, but I don’t really understand what it’s doing and how I get it to adjust the height.

editor.getSession().getDocument().getLength() *
editor.renderer.lineHeight + editor.renderer.scrollBar.getWidth()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:43:55+00:00Added an answer on June 15, 2026 at 1:43 am

    (UPDATE: I’m not working with this at the moment, but my answer may be out of date. To try and incorporate what others have provided, I’ll echo their mention of the minLines and maxLines properties, e.g.

    editor.setOptions({
        maxLines: Infinity
    });
    

    Apparently infinity is “not a very good idea, since it will disable virtual viewport even for very large documents.” So picking a limit may be better.

    For history’s sake, the old answer was:


    The post you cite is just operating on the assumption that it’s a fixed width font whose character height you know, and that you know the number of lines in the document. Multiply that together you get a pixel count for how tall the content is. The suggestion is that every time a character is pressed or a cut/paste happens (which may add or remove lines), you use JavaScript to apply this concrete new size to the items in your DOM with CSS styles.

    (They throw in the “width” of a scrollbar into a height calculation, and I honestly can’t tell you if there’s a rationale behind that or not. I’ll let someone else figure that part out.)

    Anyway…if you have soft wrap on, the number of rendered screen lines spanned may be more than the number of “actual” lines in the document. So it is better to use editor.getSession().getScreenLength() than editor.getSession().getDocument().getLength().

    I put the editor (position: absolute) inside of a section (position: relative), and it’s the only item living in that section. This code is seemingly working for me for now, I’ll update it if I learn more…!

    $(document).ready(function(){
    
        var heightUpdateFunction = function() {
    
            // http://stackoverflow.com/questions/11584061/
            var newHeight =
                      editor.getSession().getScreenLength()
                      * editor.renderer.lineHeight
                      + editor.renderer.scrollBar.getWidth();
    
            $('#editor').height(newHeight.toString() + "px");
            $('#editor-section').height(newHeight.toString() + "px");
    
            // This call is required for the editor to fix all of
            // its inner structure for adapting to a change in size
            editor.resize();
        };
    
        // Set initial size to match initial content
        heightUpdateFunction();
    
        // Whenever a change happens inside the ACE editor, update
        // the size again
        editor.getSession().on('change', heightUpdateFunction);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.