diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-09-18 10:37:59 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-09-18 10:37:59 +0200 |
commit | 77623d0a36d66b7b979c2b0a3141b99796deb860 (patch) | |
tree | 51a0d042a8e738d6f80627596bcc9d8e5b0a599d | |
parent | 3e233e1f2417b6831220c950ab4747b6c47cbda8 (diff) | |
parent | 6170381bd754490aee34e5a34558460d5c2f33f9 (diff) | |
download | redot-engine-77623d0a36d66b7b979c2b0a3141b99796deb860.tar.gz |
Merge pull request #81354 from MJacred/textedit_pixel_pos_fix
Fix `TextEdit.get_rect_at_line_column returning` negative pos even though cursor is in viewable area of the control
-rw-r--r-- | scene/gui/text_edit.cpp | 8 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 9 |
2 files changed, 16 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f28f20b584..98bedd4493 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1298,7 +1298,8 @@ void TextEdit::_notification(int p_what) { if (had_glyphs_drawn) { if (first_visible_char > glyphs[j].start) { first_visible_char = glyphs[j].start; - } else if (last_visible_char < glyphs[j].end) { + } + if (last_visible_char < glyphs[j].end) { last_visible_char = glyphs[j].end; } } @@ -4328,6 +4329,11 @@ Rect2i TextEdit::get_rect_at_line_column(int p_line, int p_column) const { ERR_FAIL_COND_V(p_column < 0, Rect2i(-1, -1, 0, 0)); ERR_FAIL_COND_V(p_column > text[p_line].length(), Rect2i(-1, -1, 0, 0)); + if (text.size() == 1 && text[0].length() == 0) { + // The TextEdit is empty. + return Rect2i(); + } + if (line_drawing_cache.size() == 0 || !line_drawing_cache.has(p_line)) { // Line is not in the cache, which means it's outside of the viewing area. return Rect2i(-1, -1, 0, 0); diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 79766cd919..7e9b472af1 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -3241,6 +3241,15 @@ TEST_CASE("[SceneTree][TextEdit] mouse") { SceneTree::get_singleton()->get_root()->add_child(text_edit); text_edit->set_size(Size2(800, 200)); + + CHECK(text_edit->get_rect_at_line_column(0, 0).get_position() == Point2i(0, 0)); + + text_edit->set_line(0, "A"); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_rect_at_line_column(0, 1).get_position().x > 0); + + text_edit->clear(); // Necessary, otherwise the following test cases fail. + text_edit->set_line(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vasius mattis leo, sed porta ex lacinia bibendum. Nunc bibendum pellentesque."); MessageQueue::get_singleton()->flush(); |