From b851514b107f14d6b164e92ed3c1c4fc5f6613b5 Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Fri, 3 May 2024 21:45:53 +0800 Subject: [PATCH] Fix uint's suffix is not highlighted in text shader editor --- editor/plugins/text_shader_editor.cpp | 2 ++ scene/resources/syntax_highlighter.cpp | 6 +++++- scene/resources/syntax_highlighter.h | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 83a17003066..a1d1df0f837 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -334,6 +334,8 @@ void ShaderTextEditor::_load_theme_settings() { warnings_panel->add_theme_font_override("normal_font", EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("main"), EditorStringName(EditorFonts))); warnings_panel->add_theme_font_size_override("normal_font_size", EditorNode::get_singleton()->get_editor_theme()->get_font_size(SNAME("main_size"), EditorStringName(EditorFonts))); } + + syntax_highlighter->set_uint_suffix_enabled(); } void ShaderTextEditor::_check_shader_mode() { diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index c7353958298..6da4215031e 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -303,7 +303,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) { } // Check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation. - if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f' || str[j] == 'e') && !in_word && prev_is_number && !is_number) { + if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f' || str[j] == 'e' || (uint_suffix_enabled && str[j] == 'u')) && !in_word && prev_is_number && !is_number) { is_number = true; is_a_symbol = false; is_char = false; @@ -617,6 +617,10 @@ void CodeHighlighter::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "color_regions"), "set_color_regions", "get_color_regions"); } +void CodeHighlighter::set_uint_suffix_enabled(bool p_enabled) { + uint_suffix_enabled = p_enabled; +} + void CodeHighlighter::set_number_color(Color p_color) { number_color = p_color; clear_highlighting_cache(); diff --git a/scene/resources/syntax_highlighter.h b/scene/resources/syntax_highlighter.h index cac2807ee20..bc66f434d41 100644 --- a/scene/resources/syntax_highlighter.h +++ b/scene/resources/syntax_highlighter.h @@ -93,6 +93,8 @@ private: Color symbol_color; Color number_color; + bool uint_suffix_enabled = false; + protected: static void _bind_methods(); @@ -139,6 +141,8 @@ public: void set_member_variable_color(Color p_color); Color get_member_variable_color() const; + + void set_uint_suffix_enabled(bool p_enabled = true); }; #endif // SYNTAX_HIGHLIGHTER_H