0 votes

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.

in Engine by (286 points)

2 Answers

0 votes

May be a combination of "cursorgetline ( )" and the signals "textchanged ( )" or "cursorchanged ( )"

by (318 points)
0 votes

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:
https://gist.github.com/MattUV/469ad2be96961c0afe8dfc1bf0932f76

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.

by (275 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.