mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 19:42:43 +00:00
Merge pull request #41459 from Paulb23/nested_color_regions
Fix colour region end key seach and start key order
This commit is contained in:
commit
d84954a281
@ -153,18 +153,16 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line)
|
||||
|
||||
/* if we are in one find the end key */
|
||||
if (in_region != -1) {
|
||||
/* check there is enough room */
|
||||
int chars_left = line_length - from;
|
||||
int end_key_length = color_regions[in_region].end_key.length();
|
||||
if (chars_left < end_key_length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* search the line */
|
||||
int region_end_index = -1;
|
||||
const CharType *end_key = color_regions[in_region].start_key.c_str();
|
||||
int end_key_length = color_regions[in_region].end_key.length();
|
||||
const CharType *end_key = color_regions[in_region].end_key.c_str();
|
||||
for (; from < line_length; from++) {
|
||||
if (!is_a_symbol) {
|
||||
if (line_length - from < end_key_length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!is_symbol(str[from])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -173,9 +171,10 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line)
|
||||
continue;
|
||||
}
|
||||
|
||||
region_end_index = from;
|
||||
for (int k = 0; k < end_key_length; k++) {
|
||||
if (end_key[k] == str[from + k]) {
|
||||
region_end_index = from;
|
||||
if (end_key[k] != str[from + k]) {
|
||||
region_end_index = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -192,7 +191,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line)
|
||||
previous_type = REGION;
|
||||
previous_text = "";
|
||||
previous_column = j;
|
||||
j = from;
|
||||
j = from + (end_key_length - 1);
|
||||
if (region_end_index == -1) {
|
||||
color_region_cache[p_line] = in_region;
|
||||
}
|
||||
@ -572,8 +571,12 @@ void GDScriptSyntaxHighlighter::add_color_region(const String &p_start_key, cons
|
||||
}
|
||||
}
|
||||
|
||||
int at = 0;
|
||||
for (int i = 0; i < color_regions.size(); i++) {
|
||||
ERR_FAIL_COND_MSG(color_regions[i].start_key == p_start_key, "color region with start key '" + p_start_key + "' already exists.");
|
||||
if (p_start_key.length() < color_regions[i].start_key.length()) {
|
||||
at++;
|
||||
}
|
||||
}
|
||||
|
||||
ColorRegion color_region;
|
||||
@ -581,7 +584,8 @@ void GDScriptSyntaxHighlighter::add_color_region(const String &p_start_key, cons
|
||||
color_region.start_key = p_start_key;
|
||||
color_region.end_key = p_end_key;
|
||||
color_region.line_only = p_line_only;
|
||||
color_regions.push_back(color_region);
|
||||
color_regions.insert(at, color_region);
|
||||
clear_highlighting_cache();
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> GDScriptSyntaxHighlighter::_create() const {
|
||||
|
@ -229,18 +229,16 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) {
|
||||
|
||||
/* if we are in one find the end key */
|
||||
if (in_region != -1) {
|
||||
/* check there is enough room */
|
||||
int chars_left = line_length - from;
|
||||
int end_key_length = color_regions[in_region].end_key.length();
|
||||
if (chars_left < end_key_length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* search the line */
|
||||
int region_end_index = -1;
|
||||
const CharType *end_key = color_regions[in_region].start_key.c_str();
|
||||
int end_key_length = color_regions[in_region].end_key.length();
|
||||
const CharType *end_key = color_regions[in_region].end_key.c_str();
|
||||
for (; from < line_length; from++) {
|
||||
if (!is_a_symbol) {
|
||||
if (line_length - from < end_key_length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!is_symbol(str[from])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -249,9 +247,10 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
region_end_index = from;
|
||||
for (int k = 0; k < end_key_length; k++) {
|
||||
if (end_key[k] == str[from + k]) {
|
||||
region_end_index = from;
|
||||
if (end_key[k] != str[from + k]) {
|
||||
region_end_index = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -265,7 +264,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) {
|
||||
highlighter_info["color"] = color_regions[in_region].color;
|
||||
color_map[j] = highlighter_info;
|
||||
|
||||
j = from;
|
||||
j = from + (end_key_length - 1);
|
||||
if (region_end_index == -1) {
|
||||
color_region_cache[p_line] = in_region;
|
||||
}
|
||||
@ -484,8 +483,12 @@ void CodeHighlighter::add_color_region(const String &p_start_key, const String &
|
||||
}
|
||||
}
|
||||
|
||||
int at = 0;
|
||||
for (int i = 0; i < color_regions.size(); i++) {
|
||||
ERR_FAIL_COND_MSG(color_regions[i].start_key == p_start_key, "color region with start key '" + p_start_key + "' already exists.");
|
||||
if (p_start_key.length() < color_regions[i].start_key.length()) {
|
||||
at++;
|
||||
}
|
||||
}
|
||||
|
||||
ColorRegion color_region;
|
||||
@ -493,7 +496,7 @@ void CodeHighlighter::add_color_region(const String &p_start_key, const String &
|
||||
color_region.start_key = p_start_key;
|
||||
color_region.end_key = p_end_key;
|
||||
color_region.line_only = p_line_only || p_end_key == "";
|
||||
color_regions.push_back(color_region);
|
||||
color_regions.insert(at, color_region);
|
||||
clear_highlighting_cache();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user