diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-09-13 19:21:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-13 19:21:25 +0200 |
commit | d85472bef05410528819b681e0c463d78075c29d (patch) | |
tree | 69280924f46a023fee2af5f09754b41c72dafa5a /editor | |
parent | d6b392825fc3e22d9e0c62f0d17633c4224eb28f (diff) | |
parent | af40c8698b6f13d351c3b996fb1b51db990e06e9 (diff) |
Merge pull request #10826 from tuga3d/toggle-comment-behavior
Smarter toggle comment block. fixes #10720
Diffstat (limited to 'editor')
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 2192d3ac49..d2cb96bf3b 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -948,13 +948,26 @@ void ScriptTextEditor::_edit_option(int p_op) { if (tx->get_selection_to_column() == 0) end -= 1; + // 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("#")) { + is_commented = false; + break; + } + } for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); - if (line_text.begins_with("#")) - line_text = line_text.substr(1, line_text.length()); - else - line_text = "#" + line_text; + if (line_text.strip_edges().empty()) { + line_text = "#"; + } else { + if (is_commented) { + line_text = line_text.substr(1, line_text.length()); + } else { + line_text = "#" + line_text; + } + } tx->set_line(i, line_text); } } else { |