|
@@ -45,7 +45,7 @@
|
|
#include "editor/editor_scale.h"
|
|
#include "editor/editor_scale.h"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
|
|
|
|
|
|
+RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) const {
|
|
if (p_free) {
|
|
if (p_free) {
|
|
if (p_item->subitems.size()) {
|
|
if (p_item->subitems.size()) {
|
|
return p_item->subitems.front()->get();
|
|
return p_item->subitems.front()->get();
|
|
@@ -90,7 +90,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
|
|
return nullptr;
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
-RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
|
|
|
|
|
|
+RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) const {
|
|
if (p_free) {
|
|
if (p_free) {
|
|
if (p_item->subitems.size()) {
|
|
if (p_item->subitems.size()) {
|
|
return p_item->subitems.back()->get();
|
|
return p_item->subitems.back()->get();
|
|
@@ -147,7 +147,7 @@ RichTextLabel::Item *RichTextLabel::_get_item_at_pos(RichTextLabel::Item *p_item
|
|
case ITEM_TEXT: {
|
|
case ITEM_TEXT: {
|
|
ItemText *t = (ItemText *)it;
|
|
ItemText *t = (ItemText *)it;
|
|
offset += t->text.length();
|
|
offset += t->text.length();
|
|
- if (offset > p_position) {
|
|
|
|
|
|
+ if (offset >= p_position) {
|
|
return it;
|
|
return it;
|
|
}
|
|
}
|
|
} break;
|
|
} break;
|
|
@@ -454,6 +454,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
|
|
ItemImage *img = (ItemImage *)it;
|
|
ItemImage *img = (ItemImage *)it;
|
|
l.text_buf->add_object((uint64_t)it, img->image->get_size(), img->inline_align, 1);
|
|
l.text_buf->add_object((uint64_t)it, img->image->get_size(), img->inline_align, 1);
|
|
text += String::chr(0xfffc);
|
|
text += String::chr(0xfffc);
|
|
|
|
+ l.char_count += 1;
|
|
} break;
|
|
} break;
|
|
case ITEM_TABLE: {
|
|
case ITEM_TABLE: {
|
|
ItemTable *table = static_cast<ItemTable *>(it);
|
|
ItemTable *table = static_cast<ItemTable *>(it);
|
|
@@ -3523,7 +3524,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p_selection) {
|
|
|
|
|
|
+String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p_selection) const {
|
|
String text;
|
|
String text;
|
|
ERR_FAIL_COND_V(p_frame == nullptr, text);
|
|
ERR_FAIL_COND_V(p_frame == nullptr, text);
|
|
ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), text);
|
|
ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), text);
|
|
@@ -3590,7 +3591,7 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p
|
|
return text;
|
|
return text;
|
|
}
|
|
}
|
|
|
|
|
|
-String RichTextLabel::get_selected_text() {
|
|
|
|
|
|
+String RichTextLabel::get_selected_text() const {
|
|
if (!selection.active || !selection.enabled) {
|
|
if (!selection.active || !selection.enabled) {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
@@ -3614,6 +3615,22 @@ bool RichTextLabel::is_selection_enabled() const {
|
|
return selection.enabled;
|
|
return selection.enabled;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int RichTextLabel::get_selection_from() const {
|
|
|
|
+ if (!selection.active || !selection.enabled) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return selection.from_frame->lines[selection.from_line].char_offset + selection.from_char;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int RichTextLabel::get_selection_to() const {
|
|
|
|
+ if (!selection.active || !selection.enabled) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return selection.to_frame->lines[selection.to_line].char_offset + selection.to_char - 1;
|
|
|
|
+}
|
|
|
|
+
|
|
void RichTextLabel::set_bbcode(const String &p_bbcode) {
|
|
void RichTextLabel::set_bbcode(const String &p_bbcode) {
|
|
bbcode = p_bbcode;
|
|
bbcode = p_bbcode;
|
|
if (is_inside_tree() && use_bbcode) {
|
|
if (is_inside_tree() && use_bbcode) {
|
|
@@ -3649,6 +3666,8 @@ String RichTextLabel::get_text() {
|
|
text += t->text;
|
|
text += t->text;
|
|
} else if (it->type == ITEM_NEWLINE) {
|
|
} else if (it->type == ITEM_NEWLINE) {
|
|
text += "\n";
|
|
text += "\n";
|
|
|
|
+ } else if (it->type == ITEM_IMAGE) {
|
|
|
|
+ text += " ";
|
|
} else if (it->type == ITEM_INDENT || it->type == ITEM_LIST) {
|
|
} else if (it->type == ITEM_INDENT || it->type == ITEM_LIST) {
|
|
text += "\t";
|
|
text += "\t";
|
|
}
|
|
}
|
|
@@ -3841,6 +3860,11 @@ void RichTextLabel::_bind_methods() {
|
|
ClassDB::bind_method(D_METHOD("set_selection_enabled", "enabled"), &RichTextLabel::set_selection_enabled);
|
|
ClassDB::bind_method(D_METHOD("set_selection_enabled", "enabled"), &RichTextLabel::set_selection_enabled);
|
|
ClassDB::bind_method(D_METHOD("is_selection_enabled"), &RichTextLabel::is_selection_enabled);
|
|
ClassDB::bind_method(D_METHOD("is_selection_enabled"), &RichTextLabel::is_selection_enabled);
|
|
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("get_selection_from"), &RichTextLabel::get_selection_from);
|
|
|
|
+ ClassDB::bind_method(D_METHOD("get_selection_to"), &RichTextLabel::get_selection_to);
|
|
|
|
+
|
|
|
|
+ ClassDB::bind_method(D_METHOD("get_selected_text"), &RichTextLabel::get_selected_text);
|
|
|
|
+
|
|
ClassDB::bind_method(D_METHOD("parse_bbcode", "bbcode"), &RichTextLabel::parse_bbcode);
|
|
ClassDB::bind_method(D_METHOD("parse_bbcode", "bbcode"), &RichTextLabel::parse_bbcode);
|
|
ClassDB::bind_method(D_METHOD("append_bbcode", "bbcode"), &RichTextLabel::append_bbcode);
|
|
ClassDB::bind_method(D_METHOD("append_bbcode", "bbcode"), &RichTextLabel::append_bbcode);
|
|
|
|
|