Browse Source

Code region keywords must be followed by whitespace

Julian 7 months ago
parent
commit
ba3f4a4b24
2 changed files with 10 additions and 2 deletions
  1. 6 0
      modules/gdscript/editor/gdscript_highlighter.cpp
  2. 4 2
      scene/gui/code_edit.cpp

+ 6 - 0
modules/gdscript/editor/gdscript_highlighter.cpp

@@ -150,6 +150,12 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
 								break;
 								break;
 							}
 							}
 						}
 						}
+						// "#region" and "#endregion" only highlighted if they're the first region on the line.
+						if (color_regions[c].type == ColorRegion::TYPE_CODE_REGION &&
+								str.strip_edges().split_spaces()[0] != "#region" &&
+								str.strip_edges().split_spaces()[0] != "#endregion") {
+							match = false;
+						}
 						if (!match) {
 						if (!match) {
 							continue;
 							continue;
 						}
 						}

+ 4 - 2
scene/gui/code_edit.cpp

@@ -1869,7 +1869,8 @@ bool CodeEdit::is_line_code_region_start(int p_line) const {
 	if (is_in_string(p_line) != -1) {
 	if (is_in_string(p_line) != -1) {
 		return false;
 		return false;
 	}
 	}
-	return get_line(p_line).strip_edges().begins_with(code_region_start_string);
+	Vector<String> split = get_line(p_line).strip_edges().split_spaces();
+	return split.size() > 0 && split[0] == code_region_start_string;
 }
 }
 
 
 bool CodeEdit::is_line_code_region_end(int p_line) const {
 bool CodeEdit::is_line_code_region_end(int p_line) const {
@@ -1880,7 +1881,8 @@ bool CodeEdit::is_line_code_region_end(int p_line) const {
 	if (is_in_string(p_line) != -1) {
 	if (is_in_string(p_line) != -1) {
 		return false;
 		return false;
 	}
 	}
-	return get_line(p_line).strip_edges().begins_with(code_region_end_string);
+	Vector<String> split = get_line(p_line).strip_edges().split_spaces();
+	return split.size() > 0 && split[0] == code_region_end_string;
 }
 }
 
 
 /* Delimiters */
 /* Delimiters */