From 481c076febb774d86e39e656347d06feb7a5da1f Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sun, 15 May 2016 01:32:43 +0100 Subject: [PATCH] Fixed hex notation highlighting (cherry picked from commit b2bf266ddc799c8421c544b860c36ba1f110ba9c) --- scene/gui/text_edit.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index b5956cdb966..ece8f62bd7e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -56,6 +56,10 @@ static bool _is_number(CharType c) { return (c >= '0' && c <= '9'); } +static bool _is_hex_symbol(CharType c) { + return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); +} + static bool _is_pair_right_symbol(CharType c) { return c == '"' || @@ -673,6 +677,7 @@ void TextEdit::_notification(int p_what) { bool in_word = false; bool in_function_name = false; bool in_member_variable = false; + bool is_hex_notation = false; Color keyword_color; // check if line contains highlighted word @@ -731,20 +736,31 @@ void TextEdit::_notification(int p_what) { in_region=-1; //reset regions that end at end of line } + // allow ABCDEF in hex notation + if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) { + is_number = true; + } else { + is_hex_notation = false; + } + + // check for dot or 'x' for hex notation in floating point number + if ((str[j] == '.' || str[j] == 'x') && !in_word && prev_is_number && !is_number) { + is_number = true; + is_symbol = false; + + if (str[j] == 'x' && str[j-1] == '0') { + is_hex_notation = true; + } + } + if (!in_word && _is_char(str[j])) { in_word = true; } - if (in_keyword || in_word) { + if ((in_keyword || in_word) && !is_hex_notation) { 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; }