mirror of
https://github.com/godotengine/godot.git
synced 2024-11-29 07:32:20 +00:00
Merge pull request #76759 from Nidjo123/master
Fix RichTextLabel character line and paragraph index getters
This commit is contained in:
commit
e38dc58199
@ -5812,10 +5812,12 @@ int RichTextLabel::get_character_line(int p_char) {
|
||||
int to_line = main->first_invalid_line.load();
|
||||
for (int i = 0; i < to_line; i++) {
|
||||
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++) {
|
||||
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;
|
||||
}
|
||||
line_count++;
|
||||
@ -5830,13 +5832,11 @@ int RichTextLabel::get_character_line(int p_char) {
|
||||
int RichTextLabel::get_character_paragraph(int p_char) {
|
||||
_validate_line_caches();
|
||||
|
||||
int para_count = 0;
|
||||
int to_line = main->first_invalid_line.load();
|
||||
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) {
|
||||
return para_count;
|
||||
} else {
|
||||
para_count++;
|
||||
int char_offset = main->lines[i].char_offset;
|
||||
if (char_offset <= p_char && p_char < char_offset + main->lines[i].char_count) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user