From 86c0438f9d8c51688353445c4f9e566a87afd204 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Tue, 5 Apr 2016 15:50:54 +0100 Subject: [PATCH] Member variable syntax highlighting (cherry picked from commit fc9f9adcb25cde432f888b8b29aee862eb0d8f95) --- scene/gui/text_edit.cpp | 16 ++++++++++++++++ scene/gui/text_edit.h | 1 + tools/editor/editor_settings.cpp | 1 + tools/editor/plugins/script_editor_plugin.cpp | 1 + 4 files changed, 19 insertions(+) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 317f8edcf8a..b5956cdb966 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -672,6 +672,7 @@ void TextEdit::_notification(int p_what) { bool in_keyword=false; bool in_word = false; bool in_function_name = false; + bool in_member_variable = false; Color keyword_color; // check if line contains highlighted word @@ -801,14 +802,28 @@ void TextEdit::_notification(int p_what) { } } + if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) { + int k = j; + while(k > 0 && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { + k--; + } + + if (str[k] == '.') { + in_member_variable = true; + } + } + if (is_symbol) { in_function_name = false; + in_member_variable = false; } if (in_region>=0) color=color_regions[in_region].color; else if (in_keyword) color=keyword_color; + else if (in_member_variable) + color=cache.member_variable_color; else if (in_function_name) color=cache.function_color; else if (is_symbol) @@ -3151,6 +3166,7 @@ void TextEdit::_update_caches() { cache.font_selected_color=get_color("font_selected_color"); cache.keyword_color=get_color("keyword_color"); cache.function_color=get_color("function_color"); + cache.member_variable_color=get_color("member_variable_color"); cache.number_color=get_color("number_color"); cache.selection_color=get_color("selection_color"); cache.mark_color=get_color("mark_color"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index f21b51f4ef4..ea4f148e915 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -80,6 +80,7 @@ class TextEdit : public Control { Color keyword_color; Color number_color; Color function_color; + Color member_variable_color; Color selection_color; Color mark_color; Color breakpoint_color; diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 9512eb48bab..e0519dd8582 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -478,6 +478,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { set("text_editor/base_type_color",Color::html("a4ffd4")); set("text_editor/engine_type_color",Color::html("83d3ff")); set("text_editor/function_color",Color::html("66a2ce")); + set("text_editor/member_variable_color",Color::html("e64e59")); set("text_editor/comment_color",Color::html("983d1b")); set("text_editor/string_color",Color::html("ef6ebe")); set("text_editor/number_color",Color::html("EB9532")); diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 2ee3f062371..4c8e0d1e00d 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -297,6 +297,7 @@ void ScriptTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/word_highlighted_color",Color(0.8,0.9,0.9,0.15))); get_text_edit()->add_color_override("number_color",EDITOR_DEF("text_editor/number_color",Color(0.9,0.6,0.0,2))); get_text_edit()->add_color_override("function_color",EDITOR_DEF("text_editor/function_color",Color(0.4,0.6,0.8))); + get_text_edit()->add_color_override("member_variable_color",EDITOR_DEF("text_editor/member_variable_color",Color(0.9,0.3,0.3))); Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));