Fix RichTextLabel character line and paragraph index getters
(cherry picked from commit e2536d0643
)
This commit is contained in:
parent
5e8654decb
commit
3b4748f6b5
|
@ -5720,10 +5720,12 @@ int RichTextLabel::get_character_line(int p_char) {
|
||||||
int to_line = main->first_invalid_line.load();
|
int to_line = main->first_invalid_line.load();
|
||||||
for (int i = 0; i < to_line; i++) {
|
for (int i = 0; i < to_line; i++) {
|
||||||
MutexLock lock(main->lines[i].text_buf->get_mutex());
|
MutexLock lock(main->lines[i].text_buf->get_mutex());
|
||||||
if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
|
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++) {
|
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
|
||||||
Vector2i range = main->lines[i].text_buf->get_line_range(j);
|
Vector2i range = main->lines[i].text_buf->get_line_range(j);
|
||||||
if (main->lines[i].char_offset + range.x < p_char && p_char <= main->lines[i].char_offset + range.y) {
|
if (char_offset + range.x <= p_char && p_char <= char_offset + range.y) {
|
||||||
return line_count;
|
return line_count;
|
||||||
}
|
}
|
||||||
line_count++;
|
line_count++;
|
||||||
|
@ -5738,13 +5740,11 @@ int RichTextLabel::get_character_line(int p_char) {
|
||||||
int RichTextLabel::get_character_paragraph(int p_char) {
|
int RichTextLabel::get_character_paragraph(int p_char) {
|
||||||
_validate_line_caches();
|
_validate_line_caches();
|
||||||
|
|
||||||
int para_count = 0;
|
|
||||||
int to_line = main->first_invalid_line.load();
|
int to_line = main->first_invalid_line.load();
|
||||||
for (int i = 0; i < to_line; i++) {
|
for (int i = 0; i < to_line; i++) {
|
||||||
if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
|
int char_offset = main->lines[i].char_offset;
|
||||||
return para_count;
|
if (char_offset <= p_char && p_char < char_offset + main->lines[i].char_count) {
|
||||||
} else {
|
return i;
|
||||||
para_count++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue