You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Update comment toggle behavior in CodeEdit
This commit is contained in:
@@ -1484,12 +1484,13 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
|
|||||||
// Check first if there's any uncommented lines in selection.
|
// Check first if there's any uncommented lines in selection.
|
||||||
bool is_commented = true;
|
bool is_commented = true;
|
||||||
for (int line = from; line <= to; line++) {
|
for (int line = from; line <= to; line++) {
|
||||||
if (!text_editor->get_line(line).begins_with(delimiter)) {
|
// `+ delimiter.length()` here because comment delimiter is not actually `in comment` so we check first character after it
|
||||||
|
int delimiter_idx = text_editor->is_in_comment(line, text_editor->get_first_non_whitespace_column(line) + delimiter.length());
|
||||||
|
if (delimiter_idx == -1 || text_editor->get_delimiter_start_key(delimiter_idx) != delimiter) {
|
||||||
is_commented = false;
|
is_commented = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caret positions need to be saved since they could be moved at the eol.
|
// Caret positions need to be saved since they could be moved at the eol.
|
||||||
Vector<int> caret_cols;
|
Vector<int> caret_cols;
|
||||||
Vector<int> selection_to_cols;
|
Vector<int> selection_to_cols;
|
||||||
@@ -1510,10 +1511,10 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_commented) {
|
if (is_commented) {
|
||||||
text_editor->set_line(line, line_text.substr(delimiter.length(), line_text.length()));
|
text_editor->set_line(line, line_text.replace_first(delimiter, ""));
|
||||||
continue;
|
} else {
|
||||||
|
text_editor->set_line(line, line_text.insert(text_editor->get_first_non_whitespace_column(line), delimiter));
|
||||||
}
|
}
|
||||||
text_editor->set_line(line, delimiter + line_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Readjust carets and selections.
|
// Readjust carets and selections.
|
||||||
|
|||||||
Reference in New Issue
Block a user