Skip to content

Commit

Permalink
Merge pull request #81064 from bruvzg/rtl_char_count_line_edge
Browse files Browse the repository at this point in the history
[RTL] Fix character line index for non-visual characters and characters on the line edge.
  • Loading branch information
akien-mga committed Aug 28, 2023
2 parents b3811a3 + 2273509 commit 713bfaf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5876,13 +5876,21 @@ int RichTextLabel::get_character_line(int p_char) {
int char_offset = main->lines[i].char_offset;
int char_count = main->lines[i].char_count;
if (char_offset <= p_char && p_char < char_offset + char_count) {
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
int lc = main->lines[i].text_buf->get_line_count();
for (int j = 0; j < lc; j++) {
Vector2i range = main->lines[i].text_buf->get_line_range(j);
if (char_offset + range.x <= p_char && p_char <= char_offset + range.y) {
return line_count;
if (char_offset + range.x <= p_char && p_char < char_offset + range.y) {
break;
}
if (char_offset + range.x > p_char && line_count > 0) {
line_count--; // Character is not rendered and is between the lines (e.g., edge space).
break;
}
if (j != lc - 1) {
line_count++;
}
line_count++;
}
return line_count;
} else {
line_count += main->lines[i].text_buf->get_line_count();
}
Expand Down

0 comments on commit 713bfaf

Please sign in to comment.