summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/gui/text_edit.cpp38
-rw-r--r--scene/gui/text_edit.h1
-rw-r--r--tools/editor/editor_settings.cpp1
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp1
4 files changed, 39 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 3948de7689..c9dd2dacf9 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -47,6 +47,15 @@ static bool _is_symbol(CharType c) {
return c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t');
}
+static bool _is_char(CharType c) {
+
+ return (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='_';
+}
+
+static bool _is_number(CharType c) {
+ return (c >= '0' && c <= '9');
+}
+
static bool _is_pair_right_symbol(CharType c) {
return
c == '"' ||
@@ -659,7 +668,9 @@ void TextEdit::_notification(int p_what) {
int char_ofs=0;
int ofs_y=i*get_row_height()+cache.line_spacing/2;
bool prev_is_char=false;
+ bool prev_is_number = false;
bool in_keyword=false;
+ bool in_word = false;
Color keyword_color;
// check if line contains highlighted word
@@ -712,13 +723,32 @@ void TextEdit::_notification(int p_what) {
color = cache.font_color; //reset
//find keyword
- bool is_char = _is_text_char(str[j]);
- bool is_symbol=_is_symbol(str[j]);
+ bool is_char = _is_text_char(str[j]);
+ bool is_symbol = _is_symbol(str[j]);
+ bool is_number = _is_number(str[j]);
if (j==0 && in_region>=0 && color_regions[in_region].line_only) {
in_region=-1; //reset regions that end at end of line
}
+ if (!in_word && _is_char(str[j])) {
+ in_word = true;
+ }
+
+ if (in_keyword || in_word) {
+ is_number = false;
+ }
+
+ // check for dot in floating point number
+ if (str[j] == '.' && !in_word && prev_is_number) {
+ is_number = true;
+ is_symbol = false;
+ }
+
+ if (is_symbol && str[j] != '.' && in_word) {
+ in_word = false;
+ }
+
if (is_symbol && cri_map.has(j)) {
@@ -767,8 +797,11 @@ void TextEdit::_notification(int p_what) {
color=keyword_color;
else if (is_symbol)
color=symbol_color;
+ else if (is_number)
+ color=cache.number_color;
prev_is_char=is_char;
+ prev_is_number=is_number;
}
int char_w;
@@ -2946,6 +2979,7 @@ void TextEdit::_update_caches() {
cache.font_color=get_color("font_color");
cache.font_selected_color=get_color("font_selected_color");
cache.keyword_color=get_color("keyword_color");
+ cache.number_color=get_color("number_color");
cache.selection_color=get_color("selection_color");
cache.mark_color=get_color("mark_color");
cache.current_line_color=get_color("current_line_color");
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 86696ca5a5..e7e6760379 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -76,6 +76,7 @@ class TextEdit : public Control {
Color font_color;
Color font_selected_color;
Color keyword_color;
+ Color number_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 6f1e90936a..b86e4cc51f 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -399,6 +399,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
set("text_editor/engine_type_color",Color::html("83d3ff"));
set("text_editor/comment_color",Color::html("983d1b"));
set("text_editor/string_color",Color::html("ef6ebe"));
+ set("text_editor/number_color",Color::html("EB9532"));
set("text_editor/symbol_color",Color::html("badfff"));
set("text_editor/selection_color",Color::html("7b5dbe"));
set("text_editor/brace_mismatch_color",Color(1,0.2,0.2));
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index b03a9301b3..4772583c55 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -293,6 +293,7 @@ void ScriptTextEditor::_load_theme_settings() {
get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2)));
get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15)));
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)));
Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));