From edf0886055d20cad14a78c0e2c74e82858117e21 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:13:56 +0300 Subject: [PATCH] [RTL] Keep tag stack between `append_text` calls. --- scene/gui/rich_text_label.cpp | 22 +++++++++++++++++++--- scene/gui/rich_text_label.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 26141663c1c..c229da9d3d2 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -3109,6 +3109,10 @@ void RichTextLabel::add_text(const String &p_text) { } void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) { + if (p_enter && !parsing_bbcode.load() && !tag_stack.is_empty()) { + tag_stack.push_back(U"?"); + } + p_item->parent = current; p_item->E = current->subitems.push_back(p_item); p_item->index = current_idx++; @@ -3984,6 +3988,9 @@ void RichTextLabel::pop() { current_frame = static_cast(current)->parent_frame; } current = current->parent; + if (!parsing_bbcode.load() && !tag_stack.is_empty()) { + tag_stack.pop_back(); + } } void RichTextLabel::pop_context() { @@ -3996,9 +4003,15 @@ void RichTextLabel::pop_context() { if (current->type == ITEM_FRAME) { current_frame = static_cast(current)->parent_frame; } else if (current->type == ITEM_CONTEXT) { + if (!parsing_bbcode.load() && !tag_stack.is_empty()) { + tag_stack.pop_back(); + } current = current->parent; return; } + if (!parsing_bbcode.load() && !tag_stack.is_empty()) { + tag_stack.pop_back(); + } current = current->parent; } } @@ -4016,6 +4029,7 @@ void RichTextLabel::clear() { set_process_internal(false); MutexLock data_lock(data_mutex); + tag_stack.clear(); main->_clear_children(); current = main; current_frame = main; @@ -4195,10 +4209,9 @@ void RichTextLabel::append_text(const String &p_bbcode) { _stop_thread(); MutexLock data_lock(data_mutex); + parsing_bbcode.store(true); + int pos = 0; - - List tag_stack; - int indent_level = 0; bool in_bold = false; @@ -5280,6 +5293,8 @@ void RichTextLabel::append_text(const String &p_bbcode) { } } } + + parsing_bbcode.store(false); } void RichTextLabel::scroll_to_selection() { @@ -6690,6 +6705,7 @@ RichTextLabel::RichTextLabel(const String &p_text) { updating.store(false); validating.store(false); stop_thread.store(false); + parsing_bbcode.store(false); set_clip_contents(true); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index a01da02b273..35551284b77 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -455,6 +455,7 @@ private: std::atomic updating; std::atomic validating; std::atomic loaded; + std::atomic parsing_bbcode; uint64_t loading_started = 0; int progress_delay = 1000; @@ -504,6 +505,7 @@ private: void _texture_changed(RID p_item); RID_PtrOwner items; + List tag_stack; String language; TextDirection text_direction = TEXT_DIRECTION_AUTO;