summaryrefslogtreecommitdiffstats
path: root/scene/gui/rich_text_label.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/rich_text_label.cpp')
-rw-r--r--scene/gui/rich_text_label.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 635f5d2d2a..2952109a78 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -1835,8 +1835,7 @@ void RichTextLabel::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
- // If `text` is empty, it could mean that the tag stack is being used instead. Leave it be.
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
}
@@ -3111,6 +3110,10 @@ void RichTextLabel::add_text(const String &p_text) {
}
void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) {
+ if (!internal_stack_editing) {
+ stack_externally_modified = true;
+ }
+
p_item->parent = current;
p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++;
@@ -3384,6 +3387,8 @@ bool RichTextLabel::remove_paragraph(int p_paragraph, bool p_no_invalidate) {
return false;
}
+ stack_externally_modified = true;
+
if (main->lines.size() == 1) {
// Clear all.
main->_clear_children();
@@ -4018,6 +4023,8 @@ void RichTextLabel::clear() {
set_process_internal(false);
MutexLock data_lock(data_mutex);
+ stack_externally_modified = false;
+
main->_clear_children();
current = main;
current_frame = main;
@@ -5820,11 +5827,19 @@ void RichTextLabel::set_text(const String &p_bbcode) {
return;
}
+ stack_externally_modified = false;
+
text = p_bbcode;
_apply_translation();
}
void RichTextLabel::_apply_translation() {
+ if (text.is_empty()) {
+ return;
+ }
+
+ internal_stack_editing = true;
+
String xl_text = atr(text);
if (use_bbcode) {
parse_bbcode(xl_text);
@@ -5832,6 +5847,8 @@ void RichTextLabel::_apply_translation() {
clear();
add_text(xl_text);
}
+
+ internal_stack_editing = false;
}
String RichTextLabel::get_text() const {
@@ -5845,8 +5862,7 @@ void RichTextLabel::set_use_bbcode(bool p_enable) {
use_bbcode = p_enable;
notify_property_list_changed();
- // If `text` is empty, it could mean that the tag stack is being used instead. Leave it be.
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
}
}
@@ -5856,7 +5872,7 @@ bool RichTextLabel::is_using_bbcode() const {
}
String RichTextLabel::get_parsed_text() const {
- String txt = "";
+ String txt;
Item *it = main;
while (it) {
if (it->type == ITEM_DROPCAP) {
@@ -5883,7 +5899,7 @@ void RichTextLabel::set_text_direction(Control::TextDirection p_text_direction)
if (text_direction != p_text_direction) {
text_direction = p_text_direction;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -5903,7 +5919,7 @@ void RichTextLabel::set_horizontal_alignment(HorizontalAlignment p_alignment) {
if (default_alignment != p_alignment) {
default_alignment = p_alignment;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -5922,7 +5938,7 @@ void RichTextLabel::set_justification_flags(BitField<TextServer::JustificationFl
if (default_jst_flags != p_flags) {
default_jst_flags = p_flags;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -5941,7 +5957,7 @@ void RichTextLabel::set_tab_stops(const PackedFloat32Array &p_tab_stops) {
if (default_tab_stops != p_tab_stops) {
default_tab_stops = p_tab_stops;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -5960,7 +5976,7 @@ void RichTextLabel::set_structured_text_bidi_override(TextServer::StructuredText
_stop_thread();
st_parser = p_parser;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -5994,7 +6010,7 @@ void RichTextLabel::set_language(const String &p_language) {
_stop_thread();
language = p_language;
- if (!text.is_empty()) {
+ if (!stack_externally_modified) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
@@ -6052,7 +6068,7 @@ float RichTextLabel::get_visible_ratio() const {
void RichTextLabel::set_effects(Array p_effects) {
custom_effects = p_effects;
- if ((!text.is_empty()) && use_bbcode) {
+ if (!stack_externally_modified && use_bbcode) {
parse_bbcode(atr(text));
}
}
@@ -6067,7 +6083,7 @@ void RichTextLabel::install_effect(const Variant effect) {
ERR_FAIL_COND_MSG(rteffect.is_null(), "Invalid RichTextEffect resource.");
custom_effects.push_back(effect);
- if ((!text.is_empty()) && use_bbcode) {
+ if (!stack_externally_modified && use_bbcode) {
parse_bbcode(atr(text));
}
}