From faebb0895f11bcbdf82853582b67323ff9d25cfb Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Fri, 13 Oct 2023 14:26:28 +0300 Subject: [PATCH] GDScript: Highlight code region comments --- .../gdscript/editor/gdscript_highlighter.cpp | 48 +++++++++---------- .../gdscript/editor/gdscript_highlighter.h | 11 ++++- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 1f07def21c8..85d2aefbc7d 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -150,7 +150,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l // Check if it's the whole line. if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) { // Don't skip comments, for highlighting markers. - if (color_regions[in_region].start_key.begins_with("#")) { + if (color_regions[in_region].type == ColorRegion::TYPE_COMMENT) { break; } if (from + end_key_length > line_length) { @@ -172,7 +172,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } // Don't skip comments, for highlighting markers. - if (j == line_length && !color_regions[in_region].start_key.begins_with("#")) { + if (j == line_length && color_regions[in_region].type != ColorRegion::TYPE_COMMENT) { continue; } } @@ -180,13 +180,13 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l // If we are in one, find the end key. if (in_region != -1) { Color region_color = color_regions[in_region].color; - if (in_node_path && (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'")) { + if (in_node_path && color_regions[in_region].type == ColorRegion::TYPE_STRING) { region_color = node_path_color; } - if (in_node_ref && (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'")) { + if (in_node_ref && color_regions[in_region].type == ColorRegion::TYPE_STRING) { region_color = node_ref_color; } - if (in_string_name && (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'")) { + if (in_string_name && color_regions[in_region].type == ColorRegion::TYPE_STRING) { region_color = string_name_color; } @@ -194,7 +194,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l highlighter_info["color"] = region_color; color_map[j] = highlighter_info; - if (color_regions[in_region].start_key.begins_with("#")) { + if (color_regions[in_region].type == ColorRegion::TYPE_COMMENT) { int marker_start_pos = from; int marker_len = 0; while (from <= line_length) { @@ -738,7 +738,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { for (const String &comment : comments) { String beg = comment.get_slice(" ", 0); String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); - add_color_region(beg, end, comment_color, end.is_empty()); + add_color_region(ColorRegion::TYPE_COMMENT, beg, end, comment_color, end.is_empty()); } /* Doc comments */ @@ -748,18 +748,20 @@ void GDScriptSyntaxHighlighter::_update_cache() { for (const String &doc_comment : doc_comments) { String beg = doc_comment.get_slice(" ", 0); String end = doc_comment.get_slice_count(" ") > 1 ? doc_comment.get_slice(" ", 1) : String(); - add_color_region(beg, end, doc_comment_color, end.is_empty()); + add_color_region(ColorRegion::TYPE_COMMENT, beg, end, doc_comment_color, end.is_empty()); } + /* Code regions */ + const Color code_region_color = Color(EDITOR_GET("text_editor/theme/highlighting/folded_code_region_color").operator Color(), 1.0); + add_color_region(ColorRegion::TYPE_CODE_REGION, "#region", "", code_region_color, true); + add_color_region(ColorRegion::TYPE_CODE_REGION, "#endregion", "", code_region_color, true); + /* Strings */ string_color = EDITOR_GET("text_editor/theme/highlighting/string_color"); - List strings; - gdscript->get_string_delimiters(&strings); - for (const String &string : strings) { - String beg = string.get_slice(" ", 0); - String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); - add_color_region(beg, end, string_color, end.is_empty()); - } + add_color_region(ColorRegion::TYPE_STRING, "\"", "\"", string_color); + add_color_region(ColorRegion::TYPE_STRING, "'", "'", string_color); + add_color_region(ColorRegion::TYPE_MULTILINE_STRING, "\"\"\"", "\"\"\"", string_color); + add_color_region(ColorRegion::TYPE_MULTILINE_STRING, "'''", "'''", string_color); const Ref