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.
_update_height() function is to expand vertically the TextEdit's size.