Merge pull request #89242 from RafaelRain18/master

Fix region section not ignoring #region and #endregion when in a string
This commit is contained in:
Rémi Verschelde 2024-03-11 14:02:30 +01:00
commit 1bbdbbaada
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 28 additions and 0 deletions

View file

@ -1861,6 +1861,9 @@ bool CodeEdit::is_line_code_region_start(int p_line) const {
if (code_region_start_string.is_empty()) {
return false;
}
if (is_in_string(p_line) != -1) {
return false;
}
return get_line(p_line).strip_edges().begins_with(code_region_start_string);
}
@ -1869,6 +1872,9 @@ bool CodeEdit::is_line_code_region_end(int p_line) const {
if (code_region_start_string.is_empty()) {
return false;
}
if (is_in_string(p_line) != -1) {
return false;
}
return get_line(p_line).strip_edges().begins_with(code_region_end_string);
}

View file

@ -3048,6 +3048,28 @@ TEST_CASE("[SceneTree][CodeEdit] region folding") {
CHECK(code_edit->get_next_visible_line_offset_from(1, 1) == 4);
code_edit->unfold_line(1);
CHECK_FALSE(code_edit->is_line_folded(0));
// Region start and end tags are ignored if in a string and at the start of the line.
code_edit->clear_comment_delimiters();
code_edit->add_comment_delimiter("#", "");
code_edit->clear_string_delimiters();
code_edit->add_string_delimiter("\"", "\"");
code_edit->set_text("#region region_name1\nline2\n\"\n#region region_name2\n#endregion\n\"\n#endregion\nvisible");
CHECK(code_edit->is_line_code_region_start(0));
CHECK(code_edit->is_line_code_region_end(6));
CHECK(code_edit->can_fold_line(0));
for (int i = 1; i < 7; i++) {
if (i == 2) {
continue;
}
CHECK_FALSE(code_edit->can_fold_line(i));
}
for (int i = 0; i < 7; i++) {
CHECK_FALSE(code_edit->is_line_folded(i));
}
code_edit->fold_line(0);
CHECK(code_edit->is_line_folded(0));
CHECK(code_edit->get_next_visible_line_offset_from(1, 1) == 7);
}
memdelete(code_edit);