@@ -3342,7 +3342,7 @@ void RichTextLabel::_remove_frame(HashSet<Item *> &r_erase_list, ItemFrame *p_fr
33423342 }
33433343}
33443344
3345- bool RichTextLabel::remove_paragraph (const int p_paragraph) {
3345+ bool RichTextLabel::remove_paragraph (int p_paragraph, bool p_no_invalidate ) {
33463346 _stop_thread ();
33473347 MutexLock data_lock (data_mutex);
33483348
@@ -3391,8 +3391,44 @@ bool RichTextLabel::remove_paragraph(const int p_paragraph) {
33913391
33923392 selection.click_frame = nullptr ;
33933393 selection.click_item = nullptr ;
3394- deselect ();
3394+ selection.active = false ;
3395+
3396+ if (p_no_invalidate) {
3397+ // Do not invalidate cache, only update vertical offsets of the paragraphs after deleted one and scrollbar.
3398+ int to_line = main->first_invalid_line .load () - 1 ;
3399+ float total_height = (p_paragraph == 0 ) ? 0 : _calculate_line_vertical_offset (main->lines [p_paragraph - 1 ]);
3400+ for (int i = p_paragraph; i < to_line; i++) {
3401+ MutexLock lock (main->lines [to_line - 1 ].text_buf ->get_mutex ());
3402+ main->lines [i].offset .y = total_height;
3403+ total_height = _calculate_line_vertical_offset (main->lines [i]);
3404+ }
3405+ updating_scroll = true ;
3406+ vscroll->set_max (total_height);
3407+ updating_scroll = false ;
3408+
3409+ main->first_invalid_line .store (MAX (main->first_invalid_line .load () - 1 , 0 ));
3410+ main->first_resized_line .store (MAX (main->first_resized_line .load () - 1 , 0 ));
3411+ main->first_invalid_font_line .store (MAX (main->first_invalid_font_line .load () - 1 , 0 ));
3412+ } else {
3413+ // Invalidate cache after the deleted paragraph.
3414+ main->first_invalid_line .store (MIN (main->first_invalid_line .load (), p_paragraph));
3415+ main->first_resized_line .store (MIN (main->first_resized_line .load (), p_paragraph));
3416+ main->first_invalid_font_line .store (MIN (main->first_invalid_font_line .load (), p_paragraph));
3417+ }
3418+ queue_redraw ();
3419+
3420+ return true ;
3421+ }
3422+
3423+ bool RichTextLabel::invalidate_paragraph (int p_paragraph) {
3424+ _stop_thread ();
3425+ MutexLock data_lock (data_mutex);
3426+
3427+ if (p_paragraph >= (int )main->lines .size () || p_paragraph < 0 ) {
3428+ return false ;
3429+ }
33953430
3431+ // Invalidate cache.
33963432 main->first_invalid_line .store (MIN (main->first_invalid_line .load (), p_paragraph));
33973433 main->first_resized_line .store (MIN (main->first_resized_line .load (), p_paragraph));
33983434 main->first_invalid_font_line .store (MIN (main->first_invalid_font_line .load (), p_paragraph));
@@ -5851,7 +5887,8 @@ void RichTextLabel::_bind_methods() {
58515887 ClassDB::bind_method (D_METHOD (" add_image" , " image" , " width" , " height" , " color" , " inline_align" , " region" , " key" , " pad" , " tooltip" , " size_in_percent" ), &RichTextLabel::add_image, DEFVAL (0 ), DEFVAL (0 ), DEFVAL (Color (1.0 , 1.0 , 1.0 )), DEFVAL (INLINE_ALIGNMENT_CENTER), DEFVAL (Rect2 ()), DEFVAL (Variant ()), DEFVAL (false ), DEFVAL (String ()), DEFVAL (false ));
58525888 ClassDB::bind_method (D_METHOD (" update_image" , " key" , " mask" , " image" , " width" , " height" , " color" , " inline_align" , " region" , " pad" , " tooltip" , " size_in_percent" ), &RichTextLabel::update_image, DEFVAL (0 ), DEFVAL (0 ), DEFVAL (Color (1.0 , 1.0 , 1.0 )), DEFVAL (INLINE_ALIGNMENT_CENTER), DEFVAL (Rect2 ()), DEFVAL (false ), DEFVAL (String ()), DEFVAL (false ));
58535889 ClassDB::bind_method (D_METHOD (" newline" ), &RichTextLabel::add_newline);
5854- ClassDB::bind_method (D_METHOD (" remove_paragraph" , " paragraph" ), &RichTextLabel::remove_paragraph);
5890+ ClassDB::bind_method (D_METHOD (" remove_paragraph" , " paragraph" , " no_invalidate" ), &RichTextLabel::remove_paragraph, DEFVAL (false ));
5891+ ClassDB::bind_method (D_METHOD (" invalidate_paragraph" , " paragraph" ), &RichTextLabel::invalidate_paragraph);
58555892 ClassDB::bind_method (D_METHOD (" push_font" , " font" , " font_size" ), &RichTextLabel::push_font, DEFVAL (0 ));
58565893 ClassDB::bind_method (D_METHOD (" push_font_size" , " font_size" ), &RichTextLabel::push_font_size);
58575894 ClassDB::bind_method (D_METHOD (" push_normal" ), &RichTextLabel::push_normal);
0 commit comments