summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-12-02 10:32:54 +0100
committerGitHub <noreply@github.com>2017-12-02 10:32:54 +0100
commit5ddf288c790b4dc6b6461ed25687e835469481c6 (patch)
treef8968a6548ac6b0e477413c06a1b4ae21c2756e0 /editor/plugins
parentabdcf2c02456619fd8aa65aa95da76046369b642 (diff)
parent07aa9d0506aa91e04ece867e9ea0aea4b7b932d3 (diff)
Merge pull request #13489 from Hinsbart/fix_toggle_comment
Script Editor: Make comment delimiter language dependent.
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/script_text_editor.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 214f24b386..19293360ed 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1039,6 +1039,13 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (scr.is_null())
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();
if (tx->is_selection_active()) {
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
bool is_commented = true;
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;
break;
}
@@ -1060,12 +1067,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
String line_text = tx->get_line(i);
if (line_text.strip_edges().empty()) {
- line_text = "#";
+ line_text = delimiter;
} else {
if (is_commented) {
- line_text = line_text.substr(1, line_text.length());
+ line_text = line_text.substr(delimiter.length(), line_text.length());
} else {
- line_text = "#" + line_text;
+ line_text = delimiter + 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();
String line_text = tx->get_line(begin);
- if (line_text.begins_with("#"))
- line_text = line_text.substr(1, line_text.length());
+ if (line_text.begins_with(delimiter))
+ line_text = line_text.substr(delimiter.length(), line_text.length());
else
- line_text = "#" + line_text;
+ line_text = delimiter + line_text;
tx->set_line(begin, line_text);
}
tx->end_complex_operation();