You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #25782 from hsandt/feature/fix-toggle-comment-indent
Feature/fix toggle comment indent
This commit is contained in:
@@ -248,19 +248,19 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
} break;
|
||||
case EDIT_INDENT_LEFT: {
|
||||
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
if (shader.is_null())
|
||||
return;
|
||||
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
tx->indent_left();
|
||||
|
||||
} break;
|
||||
case EDIT_INDENT_RIGHT: {
|
||||
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
if (shader.is_null())
|
||||
return;
|
||||
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
tx->indent_right();
|
||||
|
||||
} break;
|
||||
@@ -272,54 +272,10 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
} break;
|
||||
case EDIT_TOGGLE_COMMENT: {
|
||||
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
if (shader.is_null())
|
||||
return;
|
||||
|
||||
tx->begin_complex_operation();
|
||||
if (tx->is_selection_active()) {
|
||||
int begin = tx->get_selection_from_line();
|
||||
int end = tx->get_selection_to_line();
|
||||
|
||||
// End of selection ends on the first column of the last line, ignore it.
|
||||
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.strip_edges().empty()) {
|
||||
line_text = "//";
|
||||
} else {
|
||||
if (is_commented) {
|
||||
line_text = line_text.substr(2, line_text.length());
|
||||
} else {
|
||||
line_text = "//" + line_text;
|
||||
}
|
||||
}
|
||||
tx->set_line(i, line_text);
|
||||
}
|
||||
} else {
|
||||
int begin = tx->cursor_get_line();
|
||||
String line_text = tx->get_line(begin);
|
||||
|
||||
if (line_text.begins_with("//"))
|
||||
line_text = line_text.substr(2, line_text.length());
|
||||
else
|
||||
line_text = "//" + line_text;
|
||||
tx->set_line(begin, line_text);
|
||||
}
|
||||
tx->end_complex_operation();
|
||||
tx->update();
|
||||
//tx->deselect();
|
||||
shader_editor->toggle_inline_comment("//");
|
||||
|
||||
} break;
|
||||
case EDIT_COMPLETE: {
|
||||
|
||||
Reference in New Issue
Block a user