Skip to content

Commit 5280c0b

Browse files
committed
Merge pull request #102469 from sockeye-d/warning-highlights
Highlight warning lines in Script editor
2 parents a77a28c + eb99adb commit 5280c0b

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

doc/classes/EditorSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,9 @@
15211521
<member name="text_editor/theme/highlighting/user_type_color" type="Color" setter="" getter="">
15221522
The script editor's color for user-defined types (using [code]class_name[/code]).
15231523
</member>
1524+
<member name="text_editor/theme/highlighting/warning_color" type="Color" setter="" getter="">
1525+
The script editor's background color for lines with warnings. This should be set to a translucent color so that it can display on top of other line color modifiers such as [member text_editor/theme/highlighting/current_line_color].
1526+
</member>
15241527
<member name="text_editor/theme/highlighting/word_highlighted_color" type="Color" setter="" getter="">
15251528
The script editor's color for words highlighted by selecting them. Only visible if [member text_editor/appearance/caret/highlight_all_occurrences] is [code]true[/code].
15261529
</member>

editor/editor_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ void EditorSettings::_load_godot2_text_editor_theme() {
10831083
_initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), true);
10841084
_initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), true);
10851085
_initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), true);
1086+
_initial_set("text_editor/theme/highlighting/warning_color", Color(1.0, 0.8, 0.4, 0.1), true);
10861087
_initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
10871088
_initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
10881089
_initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));

editor/plugins/script_text_editor.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,22 @@ void ScriptTextEditor::enable_editor(Control *p_shortcut_context) {
184184
void ScriptTextEditor::_load_theme_settings() {
185185
CodeEdit *text_edit = code_editor->get_text_editor();
186186

187+
Color updated_warning_line_color = EDITOR_GET("text_editor/theme/highlighting/warning_color");
187188
Color updated_marked_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
188189
Color updated_safe_line_number_color = EDITOR_GET("text_editor/theme/highlighting/safe_line_number_color");
189190
Color updated_folded_code_region_color = EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color");
190191

191-
bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color;
192+
bool warning_line_color_updated = updated_warning_line_color != warning_line_color;
192193
bool marked_line_color_updated = updated_marked_line_color != marked_line_color;
194+
bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color;
193195
bool folded_code_region_color_updated = updated_folded_code_region_color != folded_code_region_color;
194-
if (safe_line_number_color_updated || marked_line_color_updated || folded_code_region_color_updated) {
196+
if (safe_line_number_color_updated || warning_line_color_updated || marked_line_color_updated || folded_code_region_color_updated) {
195197
safe_line_number_color = updated_safe_line_number_color;
196198
for (int i = 0; i < text_edit->get_line_count(); i++) {
199+
if (warning_line_color_updated && text_edit->get_line_background_color(i) == warning_line_color) {
200+
text_edit->set_line_background_color(i, updated_warning_line_color);
201+
}
202+
197203
if (marked_line_color_updated && text_edit->get_line_background_color(i) == marked_line_color) {
198204
text_edit->set_line_background_color(i, updated_marked_line_color);
199205
}
@@ -206,6 +212,7 @@ void ScriptTextEditor::_load_theme_settings() {
206212
text_edit->set_line_background_color(i, updated_folded_code_region_color);
207213
}
208214
}
215+
warning_line_color = updated_warning_line_color;
209216
marked_line_color = updated_marked_line_color;
210217
folded_code_region_color = updated_folded_code_region_color;
211218
}
@@ -567,8 +574,8 @@ void ScriptTextEditor::_validate_script() {
567574
script_is_valid = true;
568575
}
569576
_update_connected_methods();
570-
_update_warnings();
571577
_update_errors();
578+
_update_warnings();
572579

573580
emit_signal(SNAME("name_changed"));
574581
emit_signal(SNAME("edited_script_changed"));
@@ -637,6 +644,17 @@ void ScriptTextEditor::_update_warnings() {
637644
warnings_panel->pop(); // Cell.
638645
}
639646
warnings_panel->pop(); // Table.
647+
if (warning_line_color.a != 0.0) {
648+
CodeEdit *te = code_editor->get_text_editor();
649+
for (int i = 0; i < te->get_line_count(); i++) {
650+
for (const ScriptLanguage::Warning &W : warnings) {
651+
if (i >= W.start_line - 1 && i < W.end_line) {
652+
te->set_line_background_color(i, warning_line_color);
653+
break;
654+
}
655+
}
656+
}
657+
}
640658
}
641659

642660
void ScriptTextEditor::_update_errors() {
@@ -706,7 +724,7 @@ void ScriptTextEditor::_update_errors() {
706724
if (errors.is_empty()) {
707725
bool is_folded_code_region = te->is_line_code_region_start(i) && te->is_line_folded(i);
708726
te->set_line_background_color(i, is_folded_code_region ? folded_code_region_color : Color(0, 0, 0, 0));
709-
} else {
727+
} else if (marked_line_color.a != 0) {
710728
for (const ScriptLanguage::ScriptError &E : errors) {
711729
bool error_line = i == E.line - 1;
712730
te->set_line_background_color(i, error_line ? marked_line_color : Color(0, 0, 0, 0));
@@ -1806,8 +1824,8 @@ void ScriptTextEditor::_notification(int p_what) {
18061824
break;
18071825
}
18081826
if (is_visible_in_tree()) {
1809-
_update_warnings();
18101827
_update_errors();
1828+
_update_warnings();
18111829
}
18121830
[[fallthrough]];
18131831
case NOTIFICATION_ENTER_TREE: {

editor/plugins/script_text_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class ScriptTextEditor : public ScriptEditorBase {
9797
Color safe_line_number_color = Color(1, 1, 1);
9898

9999
Color marked_line_color = Color(1, 1, 1);
100+
Color warning_line_color = Color(1, 1, 1);
100101
Color folded_code_region_color = Color(1, 1, 1);
101102
int previous_line = 0;
102103

editor/themes/editor_theme_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,7 @@ void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_co
26092609
const Color function_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1);
26102610
const Color member_variable_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1);
26112611
const Color mark_color = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3);
2612+
const Color warning_color = Color(p_config.warning_color.r, p_config.warning_color.g, p_config.warning_color.b, 0.15);
26122613
const Color bookmark_color = Color(0.08, 0.49, 0.98);
26132614
const Color breakpoint_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1);
26142615
const Color executing_line_color = Color(0.98, 0.89, 0.27);
@@ -2652,6 +2653,7 @@ void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_co
26522653
setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true);
26532654
setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true);
26542655
setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true);
2656+
setting->set_initial_value("text_editor/theme/highlighting/warning_color", warning_color, true);
26552657
setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true);
26562658
setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true);
26572659
setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true);

0 commit comments

Comments
 (0)