@@ -601,6 +601,50 @@ void ScriptTextEditor::_update_color_constructor_options() {
601601 }
602602}
603603
604+ void ScriptTextEditor::_update_background_color () {
605+ // Clear background lines.
606+ CodeEdit *te = code_editor->get_text_editor ();
607+ for (int i = 0 ; i < te->get_line_count (); i++) {
608+ bool is_folded_code_region = te->is_line_code_region_start (i) && te->is_line_folded (i);
609+ te->set_line_background_color (i, is_folded_code_region ? folded_code_region_color : Color (0 , 0 , 0 , 0 ));
610+ }
611+
612+ // Set the warning background.
613+ if (warning_line_color.a != 0.0 ) {
614+ for (const ScriptLanguage::Warning &warning : warnings) {
615+ int folder_line_header = te->get_folded_line_header (warning.end_line - 2 );
616+ bool is_folded = folder_line_header != (warning.end_line - 2 );
617+
618+ if (is_folded) {
619+ te->set_line_background_color (folder_line_header, warning_line_color);
620+ } else if (warning.end_line - warning.start_line > 0 && warning.end_line - warning.start_line < 20 ) {
621+ // If the warning spans below 20 lines (arbitrary), set the background color for all lines.
622+ // (W.end_line - W.start_line > 0) ensures that we set the background for single line warnings.
623+ for (int i = warning.start_line - 1 ; i < warning.end_line - 1 ; i++) {
624+ te->set_line_background_color (i, warning_line_color);
625+ }
626+ } else {
627+ // Otherwise, just set the background color for the start line of the warning.
628+ te->set_line_background_color (warning.start_line - 1 , warning_line_color);
629+ }
630+ }
631+ }
632+
633+ // Set the error background.
634+ if (marked_line_color.a != 0.0 ) {
635+ for (const ScriptLanguage::ScriptError &error : errors) {
636+ int folder_line_header = te->get_folded_line_header (error.line - 1 );
637+ bool is_folded_code = folder_line_header != (error.line - 1 );
638+
639+ if (is_folded_code) {
640+ te->set_line_background_color (folder_line_header, marked_line_color);
641+ } else {
642+ te->set_line_background_color (error.line - 1 , marked_line_color);
643+ }
644+ }
645+ }
646+ }
647+
604648void ScriptTextEditor::_update_color_text () {
605649 if (inline_color_line < 0 ) {
606650 return ;
@@ -802,6 +846,7 @@ void ScriptTextEditor::_validate_script() {
802846 _update_connected_methods ();
803847 _update_warnings ();
804848 _update_errors ();
849+ _update_background_color ();
805850
806851 emit_signal (SNAME (" name_changed" ));
807852 emit_signal (SNAME (" edited_script_changed" ));
@@ -870,17 +915,6 @@ void ScriptTextEditor::_update_warnings() {
870915 warnings_panel->pop (); // Cell.
871916 }
872917 warnings_panel->pop (); // Table.
873- if (warning_line_color.a != 0.0 ) {
874- CodeEdit *te = code_editor->get_text_editor ();
875- for (int i = 0 ; i < te->get_line_count (); i++) {
876- for (const ScriptLanguage::Warning &W : warnings) {
877- if (i >= W.start_line - 1 && i < W.end_line ) {
878- te->set_line_background_color (i, warning_line_color);
879- break ;
880- }
881- }
882- }
883- }
884918}
885919
886920void ScriptTextEditor::_update_errors () {
@@ -943,23 +977,11 @@ void ScriptTextEditor::_update_errors() {
943977 errors_panel->pop (); // Indent.
944978 }
945979
946- CodeEdit *te = code_editor->get_text_editor ();
947980 bool highlight_safe = EDITOR_GET (" text_editor/appearance/gutters/highlight_type_safe_lines" );
948981 bool last_is_safe = false ;
949- for (int i = 0 ; i < te->get_line_count (); i++) {
950- if (errors.is_empty ()) {
951- bool is_folded_code_region = te->is_line_code_region_start (i) && te->is_line_folded (i);
952- te->set_line_background_color (i, is_folded_code_region ? folded_code_region_color : Color (0 , 0 , 0 , 0 ));
953- } else if (marked_line_color.a != 0 ) {
954- for (const ScriptLanguage::ScriptError &E : errors) {
955- bool error_line = i == E.line - 1 ;
956- te->set_line_background_color (i, error_line ? marked_line_color : Color (0 , 0 , 0 , 0 ));
957- if (error_line) {
958- break ;
959- }
960- }
961- }
982+ CodeEdit *te = code_editor->get_text_editor ();
962983
984+ for (int i = 0 ; i < te->get_line_count (); i++) {
963985 if (highlight_safe) {
964986 if (safe_lines.has (i + 1 )) {
965987 te->set_line_gutter_item_color (i, line_number_gutter, safe_line_number_color);
@@ -1727,11 +1749,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
17271749 } break ;
17281750 case EDIT_FOLD_ALL_LINES: {
17291751 tx->fold_all_lines ();
1730- tx->queue_redraw ();
17311752 } break ;
17321753 case EDIT_UNFOLD_ALL_LINES: {
17331754 tx->unfold_all_lines ();
1734- tx->queue_redraw ();
17351755 } break ;
17361756 case EDIT_CREATE_CODE_REGION: {
17371757 tx->create_code_region ();
@@ -2031,6 +2051,7 @@ void ScriptTextEditor::_notification(int p_what) {
20312051 if (is_visible_in_tree ()) {
20322052 _update_warnings ();
20332053 _update_errors ();
2054+ _update_background_color ();
20342055 }
20352056 [[fallthrough]];
20362057 case NOTIFICATION_ENTER_TREE: {
@@ -2588,6 +2609,7 @@ void ScriptTextEditor::_enable_code_editor() {
25882609 code_editor->get_text_editor ()->connect (" gutter_added" , callable_mp (this , &ScriptTextEditor::_update_gutter_indexes));
25892610 code_editor->get_text_editor ()->connect (" gutter_removed" , callable_mp (this , &ScriptTextEditor::_update_gutter_indexes));
25902611 code_editor->get_text_editor ()->connect (" gutter_clicked" , callable_mp (this , &ScriptTextEditor::_gutter_clicked));
2612+ code_editor->get_text_editor ()->connect (" _fold_line_updated" , callable_mp (this , &ScriptTextEditor::_update_background_color));
25912613 code_editor->get_text_editor ()->connect (SceneStringName (gui_input), callable_mp (this , &ScriptTextEditor::_text_edit_gui_input));
25922614 code_editor->show_toggle_files_button ();
25932615 _update_gutter_indexes ();
0 commit comments