Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uint's suffix is not highlighted in text shader editor #85014

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions editor/plugins/text_shader_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion scene/resources/syntax_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions scene/resources/syntax_highlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class CodeHighlighter : public SyntaxHighlighter {
Color symbol_color;
Color number_color;

bool uint_suffix_enabled = false;

protected:
static void _bind_methods();

Expand Down Expand Up @@ -139,6 +141,8 @@ class CodeHighlighter : public SyntaxHighlighter {

void set_member_variable_color(Color p_color);
Color get_member_variable_color() const;

void set_uint_suffix_enabled(bool p_enabled = true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why this setter has a default parameter. We generally don't use default parameters for setter methods by convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed @Chaosus 's suggestion for this, in this case looks like explicit is better

};

#endif // SYNTAX_HIGHLIGHTER_H
Loading