diff options
| author | Ian | 2018-01-06 16:46:31 -0500 |
|---|---|---|
| committer | Ian | 2018-01-06 18:06:09 -0500 |
| commit | b3ad2538d082fc191ad2695e68d6b4032a7e31bf (patch) | |
| tree | c2ec844a54dbff1f94612b33c18a075985255ebb /scene/gui/text_edit.cpp | |
| parent | d72a32bc54cda565aabfa5549c0cec7c29697950 (diff) | |
| download | godot-b3ad2538d082fc191ad2695e68d6b4032a7e31bf.tar.gz godot-b3ad2538d082fc191ad2695e68d6b4032a7e31bf.tar.zst godot-b3ad2538d082fc191ad2695e68d6b4032a7e31bf.zip | |
Diffstat (limited to 'scene/gui/text_edit.cpp')
| -rw-r--r-- | scene/gui/text_edit.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 881cdc48f..a3f59b54f 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3641,9 +3641,10 @@ void TextEdit::center_viewport_to_cursor() { int visible_rows = get_visible_rows(); if (h_scroll->is_visible_in_tree()) visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height()); - - int max_ofs = text.size() - (scroll_past_end_of_file_enabled ? 1 : num_lines_from(text.size() - 1, -visible_rows)); - cursor.line_ofs = CLAMP(cursor.line - num_lines_from(cursor.line - visible_rows / 2, -visible_rows / 2), 0, max_ofs); + if (text.size() >= visible_rows) { + int max_ofs = text.size() - (scroll_past_end_of_file_enabled ? 1 : MAX(num_lines_from(text.size() - 1, -visible_rows), 0)); + cursor.line_ofs = CLAMP(cursor.line - num_lines_from(MAX(cursor.line - visible_rows / 2, 0), -visible_rows / 2), 0, max_ofs); + } int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]); if (cursor_x > (cursor.x_ofs + visible_width)) |
