Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextEdit.get_rect_at_line_column returning negative pos even though cursor is in viewable area of the control #81354

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -4348,6 +4349,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);
Expand Down
9 changes: 9 additions & 0 deletions tests/scene/test_text_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading