[RTL] Keep tag stack between append_text calls.

This commit is contained in:
bruvzg 2024-10-11 09:13:56 +03:00
parent 92e51fca72
commit edf0886055
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
2 changed files with 21 additions and 3 deletions

View file

@ -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) { 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->parent = current;
p_item->E = current->subitems.push_back(p_item); p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++; p_item->index = current_idx++;
@ -3984,6 +3988,9 @@ void RichTextLabel::pop() {
current_frame = static_cast<ItemFrame *>(current)->parent_frame; current_frame = static_cast<ItemFrame *>(current)->parent_frame;
} }
current = current->parent; current = current->parent;
if (!parsing_bbcode.load() && !tag_stack.is_empty()) {
tag_stack.pop_back();
}
} }
void RichTextLabel::pop_context() { void RichTextLabel::pop_context() {
@ -3996,9 +4003,15 @@ void RichTextLabel::pop_context() {
if (current->type == ITEM_FRAME) { if (current->type == ITEM_FRAME) {
current_frame = static_cast<ItemFrame *>(current)->parent_frame; current_frame = static_cast<ItemFrame *>(current)->parent_frame;
} else if (current->type == ITEM_CONTEXT) { } else if (current->type == ITEM_CONTEXT) {
if (!parsing_bbcode.load() && !tag_stack.is_empty()) {
tag_stack.pop_back();
}
current = current->parent; current = current->parent;
return; return;
} }
if (!parsing_bbcode.load() && !tag_stack.is_empty()) {
tag_stack.pop_back();
}
current = current->parent; current = current->parent;
} }
} }
@ -4016,6 +4029,7 @@ void RichTextLabel::clear() {
set_process_internal(false); set_process_internal(false);
MutexLock data_lock(data_mutex); MutexLock data_lock(data_mutex);
tag_stack.clear();
main->_clear_children(); main->_clear_children();
current = main; current = main;
current_frame = main; current_frame = main;
@ -4195,10 +4209,9 @@ void RichTextLabel::append_text(const String &p_bbcode) {
_stop_thread(); _stop_thread();
MutexLock data_lock(data_mutex); MutexLock data_lock(data_mutex);
parsing_bbcode.store(true);
int pos = 0; int pos = 0;
List<String> tag_stack;
int indent_level = 0; int indent_level = 0;
bool in_bold = false; 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() { void RichTextLabel::scroll_to_selection() {
@ -6690,6 +6705,7 @@ RichTextLabel::RichTextLabel(const String &p_text) {
updating.store(false); updating.store(false);
validating.store(false); validating.store(false);
stop_thread.store(false); stop_thread.store(false);
parsing_bbcode.store(false);
set_clip_contents(true); set_clip_contents(true);
} }

View file

@ -455,6 +455,7 @@ private:
std::atomic<bool> updating; std::atomic<bool> updating;
std::atomic<bool> validating; std::atomic<bool> validating;
std::atomic<double> loaded; std::atomic<double> loaded;
std::atomic<bool> parsing_bbcode;
uint64_t loading_started = 0; uint64_t loading_started = 0;
int progress_delay = 1000; int progress_delay = 1000;
@ -504,6 +505,7 @@ private:
void _texture_changed(RID p_item); void _texture_changed(RID p_item);
RID_PtrOwner<Item> items; RID_PtrOwner<Item> items;
List<String> tag_stack;
String language; String language;
TextDirection text_direction = TEXT_DIRECTION_AUTO; TextDirection text_direction = TEXT_DIRECTION_AUTO;