diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 144dd41f1a1..8dbd262b22b 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -907,6 +907,8 @@ void GDScriptSyntaxHighlighter::add_color_region(const String &p_start_key, cons 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++; + } else { + break; } } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 40c276e4e04..291d578add1 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2862,7 +2862,8 @@ void CodeEdit::_update_code_region_tags() { return; } - for (int i = 0; i < delimiters.size(); i++) { + // A shorter delimiter has higher priority. + for (int i = delimiters.size() - 1; i >= 0; i--) { if (delimiters[i].type != DelimiterType::TYPE_COMMENT) { continue; } @@ -3104,6 +3105,8 @@ void CodeEdit::_add_delimiter(const String &p_start_key, const String &p_end_key ERR_FAIL_COND_MSG(delimiters[i].start_key == p_start_key, "delimiter with start key '" + p_start_key + "' already exists."); if (p_start_key.length() < delimiters[i].start_key.length()) { at++; + } else { + break; } } diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index e69ac448e4c..c3a374b5cdf 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -2944,15 +2944,15 @@ TEST_CASE("[SceneTree][CodeEdit] region folding") { CHECK(code_edit->is_line_code_region_end(2)); // Update code region delimiter when removing comment delimiter. - code_edit->set_text("//region region_name\nline2\n//endregion\n#region region_name\nline2\n#endregion"); + code_edit->set_text("#region region_name\nline2\n#endregion\n//region region_name\nline2\n//endregion"); code_edit->clear_comment_delimiters(); code_edit->add_comment_delimiter("//", ""); - code_edit->add_comment_delimiter("#", ""); + code_edit->add_comment_delimiter("#", ""); // A shorter delimiter has higher priority. CHECK(code_edit->is_line_code_region_start(0)); CHECK(code_edit->is_line_code_region_end(2)); CHECK_FALSE(code_edit->is_line_code_region_start(3)); CHECK_FALSE(code_edit->is_line_code_region_end(5)); - code_edit->remove_comment_delimiter("//"); + code_edit->remove_comment_delimiter("#"); CHECK_FALSE(code_edit->is_line_code_region_start(0)); CHECK_FALSE(code_edit->is_line_code_region_end(2)); CHECK(code_edit->is_line_code_region_start(3));