TextEdit Automatic Scrolling

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CosmicCitadel

Is there a way to make a TextArea automatically scroll to the bottom to show the most recently added text?

At the moment, when text is added to a TextArea in my project using “area.text += some text”, after the TextArea is full a vertical scroll bar appears but the TextArea doesn’t scroll to show the most recently added text. Thank you.

:bust_in_silhouette: Reply From: GameVisitor

You need to enable auto scroll like mentioned in the docs :


It looks like that applies to a RichTextLabel object while I was asking about a TexEdit object. However it appears using a RichTextLabel actually works better for what I wanted to do than using a TextEdit. Thank you for your reply.

CosmicCitadel | 2019-03-24 22:08

:bust_in_silhouette: Reply From: northman

For node type TextEdit, set_scroll_follow is not a function.
I solved by doing this…

func _on_ChatDisplay_cursor_changed():
var cl = get_node("RoomUI/ChatDisplay").get_line_count()
:bust_in_silhouette: Reply From: liss22

TextEdit.scroll_vertical value is meaning of focus line on itself
and it effects on scroll
so you need to code like this:

TextEdit.scroll_vertical = text_line_count_as_int

but it also has clamp,
so you don’t have to calculate how many lines on your TextEdit.text
just make it infinite:

TextEdit.scroll_vertical = INF

this will scroll to most recently added text on TextEdit

sample code below:

func send(text):
    // add your text first ...
    // ...
1 Like