ACE editor, fixed height

3,791 views
Skip to first unread message

Florent Georges

unread,
May 11, 2015, 4:21:38 PM5/11/15
to ace-d...@googlegroups.com
Hi,

I use ACE to "pretty print" code snippets on a web page.  It is configured as read-only, the snippets are not editable.  It is a very good solution even only to display code.

The only problem I have is that I do not want to have a fixed-size text area to write code, like an editor.  I want to display the code entirely, using exactly the vertical space needed.  Whether the code is 1-line long or several hundred of lines, I would like ACE to use exactly the vertical space needed, depending on the number of lines to display.

Is there an option to achieve that?

You can see an example at http://h2oconsulting.be/blog/oxygen-scala-plugin-repo.

Regards,

--
Florent Georges

Harutyun Amirjanyan

unread,
May 11, 2015, 4:29:28 PM5/11/15
to ace-d...@googlegroups.com
to make editor to automatically resize to fit content you can use maxLines option with a large value

editor.setOption("maxLines", 1000)

but using static highlighter plugin might be a better solution, see
https://github.com/ajaxorg/ace/blob/master/demo/static-highlighter.html#L61

Florent Georges

unread,
May 12, 2015, 1:36:11 PM5/12/15
to ace-d...@googlegroups.com
Brilliant, it works great, thank you!

The only thing I could not solve is to make it use a horizontal scrollbar when the text is larger than the page.  From your example, I would have expected `trim: true` to do exactly that, but neither false or true change anything.  See for instance the last code snippet in the following page (yes, every snippet is there twice, once using the old version, once with the version based on your links):

http://test.h2oconsulting.be/blog/oxygen-scala-plugin-repo

Thank you, regards,

--
Florent Georges

Harutyun Amirjanyan

unread,
May 14, 2015, 12:03:06 PM5/14/15
to ace-d...@googlegroups.com
trim is for trimming whitespace from textcontent of the div
to use scrollbar add css

.ace_static_highlight {
  white-space: pre;
  overflow: auto;
}

i can also add wrap option for this

Florent Georges

unread,
May 15, 2015, 9:54:21 AM5/15/15
to ace-d...@googlegroups.com
Thank you! I've added it to the CSS, and have checked it is applied
to the generated div element, but its stays as it is (no horizontal
scrollbar). Tried on Firefox and Chrome:
http://test.h2oconsulting.be/blog/oxygen-scala-plugin-repo.

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ajax.org Cloud9 Editor (Ace)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ace-discuss/8Ry41kC7I0c/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ace-discuss...@googlegroups.com.
> To post to this group, send email to ace-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ace-discuss.
> For more options, visit https://groups.google.com/d/optout.

Harutyun Amirjanyan

unread,
May 15, 2015, 10:11:25 AM5/15/15
to ace-d...@googlegroups.com

On Fri, May 15, 2015 at 5:53 PM, Florent Georges <fgeo...@gmail.com> wrote:
nk you!  I've added it to the CSS, and have checked it is applied
to the generated div element, but its stays as it is (no horizontal
scrollbar).  Tried on Firefox and Chrome:

On http://test.h2oconsulting.be/blog/oxygen-scala-plugin-repo. i see there is a conflict with another rule
with higher specificity. try

.code .ace_static_highlight {
  white-space: pre;
  overflow: auto;
}

Florent Georges

unread,
May 16, 2015, 7:43:37 AM5/16/15
to ace-d...@googlegroups.com
And I thought I checked for conflicts... Works perfect, thank you!
Reply all
Reply to author
Forward
0 new messages