Skip to content

Commit 40b1ce6

Browse files
committed
Merge pull request godotengine#81064 from bruvzg/rtl_char_count_line_edge
[RTL] Fix character line index for non-visual characters and characters on the line edge.
2 parents 92e892a + ae0e998 commit 40b1ce6

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

scene/gui/rich_text_label.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5876,13 +5876,21 @@ int RichTextLabel::get_character_line(int p_char) {
58765876
int char_offset = main->lines[i].char_offset;
58775877
int char_count = main->lines[i].char_count;
58785878
if (char_offset <= p_char && p_char < char_offset + char_count) {
5879-
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
5879+
int lc = main->lines[i].text_buf->get_line_count();
5880+
for (int j = 0; j < lc; j++) {
58805881
Vector2i range = main->lines[i].text_buf->get_line_range(j);
5881-
if (char_offset + range.x <= p_char && p_char <= char_offset + range.y) {
5882-
return line_count;
5882+
if (char_offset + range.x <= p_char && p_char < char_offset + range.y) {
5883+
break;
5884+
}
5885+
if (char_offset + range.x > p_char && line_count > 0) {
5886+
line_count--; // Character is not rendered and is between the lines (e.g., edge space).
5887+
break;
5888+
}
5889+
if (j != lc - 1) {
5890+
line_count++;
58835891
}
5884-
line_count++;
58855892
}
5893+
return line_count;
58865894
} else {
58875895
line_count += main->lines[i].text_buf->get_line_count();
58885896
}

0 commit comments

Comments
 (0)