@@ -605,6 +605,50 @@ void ScriptTextEditor::_update_color_constructor_options() {
605605 }
606606}
607607
608+ void ScriptTextEditor::_update_background_color () {
609+ // Clear background lines.
610+ CodeEdit *te = code_editor->get_text_editor ();
611+ for (int i = 0 ; i < te->get_line_count (); i++) {
612+ bool is_folded_code_region = te->is_line_code_region_start (i) && te->is_line_folded (i);
613+ te->set_line_background_color (i, is_folded_code_region ? folded_code_region_color : Color (0 , 0 , 0 , 0 ));
614+ }
615+
616+ // Set the warning background.
617+ if (warning_line_color.a != 0.0 ) {
618+ for (const ScriptLanguage::Warning &warning : warnings) {
619+ int folder_line_header = te->get_folded_line_header (warning.end_line - 2 );
620+ bool is_folded = folder_line_header != (warning.end_line - 2 );
621+
622+ if (is_folded) {
623+ te->set_line_background_color (folder_line_header, warning_line_color);
624+ } else if (warning.end_line - warning.start_line > 0 && warning.end_line - warning.start_line < 20 ) {
625+ // If the warning spans below 20 lines (arbitrary), set the background color for all lines.
626+ // (W.end_line - W.start_line > 0) ensures that we set the background for single line warnings.
627+ for (int i = warning.start_line - 1 ; i < warning.end_line - 1 ; i++) {
628+ te->set_line_background_color (i, warning_line_color);
629+ }
630+ } else {
631+ // Otherwise, just set the background color for the start line of the warning.
632+ te->set_line_background_color (warning.start_line - 1 , warning_line_color);
633+ }
634+ }
635+ }
636+
637+ // Set the error background.
638+ if (marked_line_color.a != 0.0 ) {
639+ for (const ScriptLanguage::ScriptError &error : errors) {
640+ int folder_line_header = te->get_folded_line_header (error.line - 1 );
641+ bool is_folded_code = folder_line_header != (error.line - 1 );
642+
643+ if (is_folded_code) {
644+ te->set_line_background_color (folder_line_header, marked_line_color);
645+ } else {
646+ te->set_line_background_color (error.line - 1 , marked_line_color);
647+ }
648+ }
649+ }
650+ }
651+
608652void ScriptTextEditor::_update_color_text () {
609653 if (inline_color_line < 0 ) {
610654 return ;
@@ -806,6 +850,7 @@ void ScriptTextEditor::_validate_script() {
806850 _update_connected_methods ();
807851 _update_warnings ();
808852 _update_errors ();
853+ _update_background_color ();
809854
810855 emit_signal (SNAME (" name_changed" ));
811856 emit_signal (SNAME (" edited_script_changed" ));
@@ -874,17 +919,6 @@ void ScriptTextEditor::_update_warnings() {
874919 warnings_panel->pop (); // Cell.
875920 }
876921 warnings_panel->pop (); // Table.
877- if (warning_line_color.a != 0.0 ) {
878- CodeEdit *te = code_editor->get_text_editor ();
879- for (int i = 0 ; i < te->get_line_count (); i++) {
880- for (const ScriptLanguage::Warning &W : warnings) {
881- if (i >= W.start_line - 1 && i < W.end_line ) {
882- te->set_line_background_color (i, warning_line_color);
883- break ;
884- }
885- }
886- }
887- }
888922}
889923
890924void ScriptTextEditor::_update_errors () {
@@ -947,23 +981,11 @@ void ScriptTextEditor::_update_errors() {
947981 errors_panel->pop (); // Indent.
948982 }
949983
950- CodeEdit *te = code_editor->get_text_editor ();
951984 bool highlight_safe = EDITOR_GET (" text_editor/appearance/gutters/highlight_type_safe_lines" );
952985 bool last_is_safe = false ;
953- for (int i = 0 ; i < te->get_line_count (); i++) {
954- if (errors.is_empty ()) {
955- bool is_folded_code_region = te->is_line_code_region_start (i) && te->is_line_folded (i);
956- te->set_line_background_color (i, is_folded_code_region ? folded_code_region_color : Color (0 , 0 , 0 , 0 ));
957- } else if (marked_line_color.a != 0 ) {
958- for (const ScriptLanguage::ScriptError &E : errors) {
959- bool error_line = i == E.line - 1 ;
960- te->set_line_background_color (i, error_line ? marked_line_color : Color (0 , 0 , 0 , 0 ));
961- if (error_line) {
962- break ;
963- }
964- }
965- }
986+ CodeEdit *te = code_editor->get_text_editor ();
966987
988+ for (int i = 0 ; i < te->get_line_count (); i++) {
967989 if (highlight_safe) {
968990 if (safe_lines.has (i + 1 )) {
969991 te->set_line_gutter_item_color (i, line_number_gutter, safe_line_number_color);
@@ -1731,11 +1753,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
17311753 } break ;
17321754 case EDIT_FOLD_ALL_LINES: {
17331755 tx->fold_all_lines ();
1734- tx->queue_redraw ();
17351756 } break ;
17361757 case EDIT_UNFOLD_ALL_LINES: {
17371758 tx->unfold_all_lines ();
1738- tx->queue_redraw ();
17391759 } break ;
17401760 case EDIT_CREATE_CODE_REGION: {
17411761 tx->create_code_region ();
@@ -2037,6 +2057,7 @@ void ScriptTextEditor::_notification(int p_what) {
20372057 if (is_visible_in_tree ()) {
20382058 _update_warnings ();
20392059 _update_errors ();
2060+ _update_background_color ();
20402061 }
20412062 [[fallthrough]];
20422063 case NOTIFICATION_ENTER_TREE: {
@@ -2594,6 +2615,7 @@ void ScriptTextEditor::_enable_code_editor() {
25942615 code_editor->get_text_editor ()->connect (" gutter_added" , callable_mp (this , &ScriptTextEditor::_update_gutter_indexes));
25952616 code_editor->get_text_editor ()->connect (" gutter_removed" , callable_mp (this , &ScriptTextEditor::_update_gutter_indexes));
25962617 code_editor->get_text_editor ()->connect (" gutter_clicked" , callable_mp (this , &ScriptTextEditor::_gutter_clicked));
2618+ code_editor->get_text_editor ()->connect (" _fold_line_updated" , callable_mp (this , &ScriptTextEditor::_update_background_color));
25972619 code_editor->get_text_editor ()->connect (SceneStringName (gui_input), callable_mp (this , &ScriptTextEditor::_text_edit_gui_input));
25982620 code_editor->show_toggle_files_button ();
25992621 _update_gutter_indexes ();
0 commit comments