Skip to content

Commit

Permalink
Merge pull request #42775 from Paulb23/code_edit_line_background
Browse files Browse the repository at this point in the history
Add custom background line colour to TextEdit and remove marked lines
  • Loading branch information
akien-mga authored May 22, 2021
2 parents 78861fd + 00e10a8 commit 4828667
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 184 deletions.
2 changes: 0 additions & 2 deletions doc/classes/CodeEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@
</theme_item>
<theme_item name="line_spacing" type="int" default="4">
</theme_item>
<theme_item name="mark_color" type="Color" default="Color( 1, 0.4, 0.4, 0.4 )">
</theme_item>
<theme_item name="normal" type="StyleBox">
</theme_item>
<theme_item name="outline_size" type="int" default="0">
Expand Down
23 changes: 20 additions & 3 deletions doc/classes/TextEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@
Returns the text of a specific line.
</description>
</method>
<method name="get_line_background_color">
<return type="Color">
</return>
<argument index="0" name="line" type="int">
</argument>
<description>
Returns the current background color of the line. [code]Color(0, 0, 0, 0)[/code] is returned if no color is set.
</description>
</method>
<method name="get_line_count" qualifiers="const">
<return type="int">
</return>
Expand Down Expand Up @@ -548,6 +557,17 @@
If [code]true[/code], hides the line of the specified index.
</description>
</method>
<method name="set_line_background_color">
<return type="void">
</return>
<argument index="0" name="line" type="int">
</argument>
<argument index="1" name="color" type="Color">
</argument>
<description>
Sets the current background color of the line. Set to [code]Color(0, 0, 0, 0)[/code] for no color.
</description>
</method>
<method name="set_line_gutter_clickable">
<return type="void">
</return>
Expand Down Expand Up @@ -987,9 +1007,6 @@
<theme_item name="line_spacing" type="int" default="4">
Sets the spacing between the lines.
</theme_item>
<theme_item name="mark_color" type="Color" default="Color( 1, 0.4, 0.4, 0.4 )">
Sets the [Color] of marked text.
</theme_item>
<theme_item name="normal" type="StyleBox">
Sets the [StyleBox] of this [TextEdit].
</theme_item>
Expand Down
34 changes: 30 additions & 4 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,34 @@ void CodeTextEditor::goto_error() {
}
}

void CodeTextEditor::_update_text_editor_theme() {
text_editor->add_theme_color_override("background_color", EDITOR_GET("text_editor/highlighting/background_color"));
text_editor->add_theme_color_override("completion_background_color", EDITOR_GET("text_editor/highlighting/completion_background_color"));
text_editor->add_theme_color_override("completion_selected_color", EDITOR_GET("text_editor/highlighting/completion_selected_color"));
text_editor->add_theme_color_override("completion_existing_color", EDITOR_GET("text_editor/highlighting/completion_existing_color"));
text_editor->add_theme_color_override("completion_scroll_color", EDITOR_GET("text_editor/highlighting/completion_scroll_color"));
text_editor->add_theme_color_override("completion_font_color", EDITOR_GET("text_editor/highlighting/completion_font_color"));
text_editor->add_theme_color_override("font_color", EDITOR_GET("text_editor/highlighting/text_color"));
text_editor->add_theme_color_override("line_number_color", EDITOR_GET("text_editor/highlighting/line_number_color"));
text_editor->add_theme_color_override("caret_color", EDITOR_GET("text_editor/highlighting/caret_color"));
text_editor->add_theme_color_override("caret_background_color", EDITOR_GET("text_editor/highlighting/caret_background_color"));
text_editor->add_theme_color_override("font_selected_color", EDITOR_GET("text_editor/highlighting/text_selected_color"));
text_editor->add_theme_color_override("selection_color", EDITOR_GET("text_editor/highlighting/selection_color"));
text_editor->add_theme_color_override("brace_mismatch_color", EDITOR_GET("text_editor/highlighting/brace_mismatch_color"));
text_editor->add_theme_color_override("current_line_color", EDITOR_GET("text_editor/highlighting/current_line_color"));
text_editor->add_theme_color_override("line_length_guideline_color", EDITOR_GET("text_editor/highlighting/line_length_guideline_color"));
text_editor->add_theme_color_override("word_highlighted_color", EDITOR_GET("text_editor/highlighting/word_highlighted_color"));
text_editor->add_theme_color_override("bookmark_color", EDITOR_GET("text_editor/highlighting/bookmark_color"));
text_editor->add_theme_color_override("breakpoint_color", EDITOR_GET("text_editor/highlighting/breakpoint_color"));
text_editor->add_theme_color_override("executing_line_color", EDITOR_GET("text_editor/highlighting/executing_line_color"));
text_editor->add_theme_color_override("code_folding_color", EDITOR_GET("text_editor/highlighting/code_folding_color"));
text_editor->add_theme_color_override("search_result_color", EDITOR_GET("text_editor/highlighting/search_result_color"));
text_editor->add_theme_color_override("search_result_border_color", EDITOR_GET("text_editor/highlighting/search_result_border_color"));
text_editor->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
emit_signal("load_theme_settings");
_load_theme_settings();
}

void CodeTextEditor::_update_font() {
text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
text_editor->add_theme_font_size_override("font_size", get_theme_font_size("source_size", "EditorFonts"));
Expand All @@ -1497,6 +1525,7 @@ void CodeTextEditor::_update_font() {
}

void CodeTextEditor::_on_settings_change() {
_update_text_editor_theme();
_update_font();

font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size");
Expand Down Expand Up @@ -1583,14 +1612,11 @@ void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) {

void CodeTextEditor::_notification(int p_what) {
switch (p_what) {
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
_load_theme_settings();
emit_signal("load_theme_settings");
} break;
case NOTIFICATION_THEME_CHANGED: {
if (toggle_scripts_button->is_visible()) {
update_toggle_scripts_button();
}
_update_text_editor_theme();
_update_font();
} break;
case NOTIFICATION_ENTER_TREE: {
Expand Down
1 change: 1 addition & 0 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class CodeTextEditor : public VBoxContainer {

void _on_settings_change();

void _update_text_editor_theme();
void _update_font();
void _complete_request();
Ref<Texture2D> _get_completion_icon(const ScriptCodeCompletionOption &p_option);
Expand Down
65 changes: 12 additions & 53 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,66 +170,25 @@ void ScriptTextEditor::_load_theme_settings() {
CodeEdit *text_edit = code_editor->get_text_editor();
text_edit->clear_keywords();

Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color updated_safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color");
if (updated_safe_line_number_color != safe_line_number_color) {

bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color;
bool marked_line_color_updated = updated_marked_line_color != marked_line_color;
if (safe_line_number_color_updated || marked_line_color_updated) {
safe_line_number_color = updated_safe_line_number_color;
for (int i = 0; i < text_edit->get_line_count(); i++) {
if (text_edit->get_line_gutter_item_color(i, line_number_gutter) != default_line_number_color) {
if (marked_line_color_updated && text_edit->get_line_background_color(i) == marked_line_color) {
text_edit->set_line_background_color(i, updated_marked_line_color);
}

if (safe_line_number_color_updated && text_edit->get_line_gutter_item_color(i, line_number_gutter) != default_line_number_color) {
text_edit->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
}
}
marked_line_color = updated_marked_line_color;
}

Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");

text_edit->add_theme_color_override("background_color", background_color);
text_edit->add_theme_color_override("completion_background_color", completion_background_color);
text_edit->add_theme_color_override("completion_selected_color", completion_selected_color);
text_edit->add_theme_color_override("completion_existing_color", completion_existing_color);
text_edit->add_theme_color_override("completion_scroll_color", completion_scroll_color);
text_edit->add_theme_color_override("completion_font_color", completion_font_color);
text_edit->add_theme_color_override("font_color", text_color);
text_edit->add_theme_color_override("line_number_color", line_number_color);
text_edit->add_theme_color_override("caret_color", caret_color);
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
text_edit->add_theme_color_override("font_selected_color", text_selected_color);
text_edit->add_theme_color_override("selection_color", selection_color);
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
text_edit->add_theme_color_override("current_line_color", current_line_color);
text_edit->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
text_edit->add_theme_color_override("word_highlighted_color", word_highlighted_color);
text_edit->add_theme_color_override("bookmark_color", bookmark_color);
text_edit->add_theme_color_override("breakpoint_color", breakpoint_color);
text_edit->add_theme_color_override("executing_line_color", executing_line_color);
text_edit->add_theme_color_override("mark_color", mark_color);
text_edit->add_theme_color_override("code_folding_color", code_folding_color);
text_edit->add_theme_color_override("search_result_color", search_result_color);
text_edit->add_theme_color_override("search_result_border_color", search_result_border_color);

text_edit->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));

theme_loaded = true;
if (!script.is_null()) {
_set_theme_for_script();
Expand Down Expand Up @@ -546,7 +505,7 @@ void ScriptTextEditor::_validate_script() {
bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
bool last_is_safe = false;
for (int i = 0; i < te->get_line_count(); i++) {
te->set_line_as_marked(i, line == i);
te->set_line_background_color(i, (line == i) ? marked_line_color : Color(0, 0, 0, 0));
if (highlight_safe) {
if (safe_lines.has(i + 1)) {
te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/script_text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class ScriptTextEditor : public ScriptEditorBase {
Color default_line_number_color = Color(1, 1, 1);
Color safe_line_number_color = Color(1, 1, 1);

Color marked_line_color = Color(1, 1, 1);

PopupPanel *color_panel = nullptr;
ColorPicker *color_picker = nullptr;
Vector2 color_position;
Expand Down
63 changes: 13 additions & 50 deletions editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,53 +83,16 @@ void ShaderTextEditor::reload_text() {
}

void ShaderTextEditor::_load_theme_settings() {
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");

get_text_editor()->add_theme_color_override("background_color", background_color);
get_text_editor()->add_theme_color_override("completion_background_color", completion_background_color);
get_text_editor()->add_theme_color_override("completion_selected_color", completion_selected_color);
get_text_editor()->add_theme_color_override("completion_existing_color", completion_existing_color);
get_text_editor()->add_theme_color_override("completion_scroll_color", completion_scroll_color);
get_text_editor()->add_theme_color_override("completion_font_color", completion_font_color);
get_text_editor()->add_theme_color_override("font_color", text_color);
get_text_editor()->add_theme_color_override("line_number_color", line_number_color);
get_text_editor()->add_theme_color_override("caret_color", caret_color);
get_text_editor()->add_theme_color_override("caret_background_color", caret_background_color);
get_text_editor()->add_theme_color_override("font_selected_color", text_selected_color);
get_text_editor()->add_theme_color_override("selection_color", selection_color);
get_text_editor()->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
get_text_editor()->add_theme_color_override("current_line_color", current_line_color);
get_text_editor()->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
get_text_editor()->add_theme_color_override("word_highlighted_color", word_highlighted_color);
get_text_editor()->add_theme_color_override("mark_color", mark_color);
get_text_editor()->add_theme_color_override("bookmark_color", bookmark_color);
get_text_editor()->add_theme_color_override("breakpoint_color", breakpoint_color);
get_text_editor()->add_theme_color_override("executing_line_color", executing_line_color);
get_text_editor()->add_theme_color_override("code_folding_color", code_folding_color);
get_text_editor()->add_theme_color_override("search_result_color", search_result_color);
get_text_editor()->add_theme_color_override("search_result_border_color", search_result_border_color);
CodeEdit *text_editor = get_text_editor();
Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color");
if (updated_marked_line_color != marked_line_color) {
for (int i = 0; i < text_editor->get_line_count(); i++) {
if (text_editor->get_line_background_color(i) == marked_line_color) {
text_editor->set_line_background_color(i, updated_marked_line_color);
}
}
marked_line_color = updated_marked_line_color;
}

syntax_highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color"));
syntax_highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color"));
Expand Down Expand Up @@ -231,13 +194,13 @@ void ShaderTextEditor::_validate_script() {
set_error(error_text);
set_error_pos(sl.get_error_line() - 1, 0);
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
get_text_editor()->set_line_as_marked(i, false);
get_text_editor()->set_line_background_color(i, Color(0, 0, 0, 0));
}
get_text_editor()->set_line_as_marked(sl.get_error_line() - 1, true);
get_text_editor()->set_line_background_color(sl.get_error_line() - 1, marked_line_color);

} else {
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
get_text_editor()->set_line_as_marked(i, false);
get_text_editor()->set_line_background_color(i, Color(0, 0, 0, 0));
}
set_error("");
}
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/shader_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class ShaderTextEditor : public CodeTextEditor {
GDCLASS(ShaderTextEditor, CodeTextEditor);

Color marked_line_color = Color(1, 1, 1);

Ref<CodeHighlighter> syntax_highlighter;
Ref<Shader> shader;

Expand Down
Loading

0 comments on commit 4828667

Please sign in to comment.