diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-03-22 07:34:08 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-03-22 07:34:08 +0100 |
commit | e8ee4f79734af75cb04c3220f83e8735d28dd6e7 (patch) | |
tree | ca191f36c13275ef4722ee06e1519e27cbc99db1 /scene/gui | |
parent | 8c2771b6d5f0a50d8b7c9587da8116667d42e03a (diff) | |
parent | c844c2d604ab7e8824659e1f6b6011039a552cbe (diff) |
Merge pull request #4115 from Paulb23/number_syntax_highlighting
Syntax highlighting for numbers
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/text_edit.cpp | 38 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
2 files changed, 37 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; |