diff options
author | cdemirer <41021322+cdemirer@users.noreply.github.com> | 2021-12-11 10:03:24 +0800 |
---|---|---|
committer | cdemirer <41021322+cdemirer@users.noreply.github.com> | 2021-12-11 10:03:24 +0800 |
commit | a361236526d1b694b15e176132830b51c171328a (patch) | |
tree | b8b3bae8703b4bee8cc5117a7dbc01bfcc3a7ace | |
parent | 04fac59f3fc035ec75a7d9b46621dd75ec9d8483 (diff) | |
download | redot-engine-a361236526d1b694b15e176132830b51c171328a.tar.gz |
Fix unexpected scroll on resize + consistent return value
-rw-r--r-- | scene/gui/text_edit.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c54b4dda00..52cbc99a22 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4226,7 +4226,10 @@ double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const { return p_line; } - double new_line_scroll_pos = get_visible_line_count_in_range(0, CLAMP(p_line, 0, text.size() - 1)); + double new_line_scroll_pos = 0.0; + if (p_line > 0) { + new_line_scroll_pos = get_visible_line_count_in_range(0, MIN(p_line - 1, text.size() - 1)); + } new_line_scroll_pos += p_wrap_index; return new_line_scroll_pos; } @@ -4290,7 +4293,7 @@ int TextEdit::get_visible_line_count_in_range(int p_from_line, int p_to_line) co /* Returns the total number of (lines + wrapped - hidden). */ if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) { - return p_to_line - p_from_line; + return (p_to_line - p_from_line) + 1; } int total_rows = 0; |