Merge pull request #13489 from Hinsbart/fix_toggle_comment

Script Editor: Make comment delimiter language dependent.
This commit is contained in:
Rémi Verschelde 2017-12-02 10:32:54 +01:00 committed by GitHub
commit 5ddf288c79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1039,6 +1039,13 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (scr.is_null()) if (scr.is_null())
return; return;
String delimiter = "#";
List<String> comment_delimiters;
scr->get_language()->get_comment_delimiters(&comment_delimiters);
if (!comment_delimiters.empty()) {
delimiter = comment_delimiters.front()->get();
}
tx->begin_complex_operation(); tx->begin_complex_operation();
if (tx->is_selection_active()) { if (tx->is_selection_active()) {
int begin = tx->get_selection_from_line(); int begin = tx->get_selection_from_line();
@ -1051,7 +1058,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
// Check if all lines in the selected block are commented // Check if all lines in the selected block are commented
bool is_commented = true; bool is_commented = true;
for (int i = begin; i <= end; i++) { for (int i = begin; i <= end; i++) {
if (!tx->get_line(i).begins_with("#")) { if (!tx->get_line(i).begins_with(delimiter)) {
is_commented = false; is_commented = false;
break; break;
} }
@ -1060,12 +1067,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
String line_text = tx->get_line(i); String line_text = tx->get_line(i);
if (line_text.strip_edges().empty()) { if (line_text.strip_edges().empty()) {
line_text = "#"; line_text = delimiter;
} else { } else {
if (is_commented) { if (is_commented) {
line_text = line_text.substr(1, line_text.length()); line_text = line_text.substr(delimiter.length(), line_text.length());
} else { } else {
line_text = "#" + line_text; line_text = delimiter + line_text;
} }
} }
tx->set_line(i, line_text); tx->set_line(i, line_text);
@ -1074,10 +1081,10 @@ void ScriptTextEditor::_edit_option(int p_op) {
int begin = tx->cursor_get_line(); int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin); String line_text = tx->get_line(begin);
if (line_text.begins_with("#")) if (line_text.begins_with(delimiter))
line_text = line_text.substr(1, line_text.length()); line_text = line_text.substr(delimiter.length(), line_text.length());
else else
line_text = "#" + line_text; line_text = delimiter + line_text;
tx->set_line(begin, line_text); tx->set_line(begin, line_text);
} }
tx->end_complex_operation(); tx->end_complex_operation();