Is it possible to detect when line is wrapped in text edit node?

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

I am working on the master branch of Godot with the textEdit node that is now able to wrap. I want to be able to expand the text edit node if the user writes greater than its initial size. However, I currently can’t find a way of 1) disabling v scroll or 2) detecting the number of lines wrapped. get_line_count does not treat wrapped lines as a new line so I am not able to do it this way.

Thanks in advance.

:bust_in_silhouette: Reply From: hinasis

May be a combination of “cursor_get_line ( )” and the signals “text_changed ( )” or “cursor_changed ( )”

:bust_in_silhouette: Reply From: Matt_UV

Hello!
There is no built in function for that, but there is a way around:

For each line, divide the text width by the (TextEdit width minus the scrollbar width), and it gives you the number of actual lines.

Here is a code snippet:

I first get the line spacing constant, depending on whether I use a theme, or custom constants. Then, I get the font and calculate how high is a line of text. At the end, I use _get_real_line_count() to know how many lines are displayed.

The _update_height() function is to expand vertically the TextEdit’s size.