Skip to content

Commit eb99adb

Browse files
committed
Added warning line highlight
1 parent a63a8b4 commit eb99adb

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
@@ -1498,6 +1498,9 @@
14981498
<member name="text_editor/theme/highlighting/user_type_color" type="Color" setter="" getter="">
14991499
The script editor's color for user-defined types (using [code]class_name[/code]).
15001500
</member>
1501+
<member name="text_editor/theme/highlighting/warning_color" type="Color" setter="" getter="">
1502+
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].
1503+
</member>
15011504
<member name="text_editor/theme/highlighting/word_highlighted_color" type="Color" setter="" getter="">
15021505
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].
15031506
</member>

editor/editor_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,7 @@ void EditorSettings::_load_godot2_text_editor_theme() {
10751075
_initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), true);
10761076
_initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), true);
10771077
_initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), true);
1078+
_initial_set("text_editor/theme/highlighting/warning_color", Color(1.0, 0.8, 0.4, 0.1), true);
10781079
_initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
10791080
_initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
10801081
_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));
@@ -1807,8 +1825,8 @@ void ScriptTextEditor::_notification(int p_what) {
18071825
break;
18081826
}
18091827
if (is_visible_in_tree()) {
1810-
_update_warnings();
18111828
_update_errors();
1829+
_update_warnings();
18121830
}
18131831
[[fallthrough]];
18141832
case NOTIFICATION_ENTER_TREE: {

editor/plugins/script_text_editor.h

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

100100
Color marked_line_color = Color(1, 1, 1);
101+
Color warning_line_color = Color(1, 1, 1);
101102
Color folded_code_region_color = Color(1, 1, 1);
102103
int previous_line = 0;
103104

editor/themes/editor_theme_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,7 @@ void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_co
26082608
const Color function_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1);
26092609
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);
26102610
const Color mark_color = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3);
2611+
const Color warning_color = Color(p_config.warning_color.r, p_config.warning_color.g, p_config.warning_color.b, 0.15);
26112612
const Color bookmark_color = Color(0.08, 0.49, 0.98);
26122613
const Color breakpoint_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1);
26132614
const Color executing_line_color = Color(0.98, 0.89, 0.27);
@@ -2651,6 +2652,7 @@ void EditorThemeManager::_generate_text_editor_defaults(ThemeConfiguration &p_co
26512652
setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true);
26522653
setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true);
26532654
setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true);
2655+
setting->set_initial_value("text_editor/theme/highlighting/warning_color", warning_color, true);
26542656
setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true);
26552657
setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true);
26562658
setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true);

0 commit comments

Comments
 (0)