mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Implement trim_final_newlines functionality
This commit is contained in:
parent
d4f726f3ef
commit
b4c1634b52
13 changed files with 99 additions and 4 deletions
|
@ -1123,6 +1123,31 @@ void CodeTextEditor::trim_trailing_whitespace() {
|
|||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::trim_final_newlines() {
|
||||
int final_line = text_editor->get_line_count() - 1;
|
||||
int check_line = final_line;
|
||||
|
||||
String line = text_editor->get_line(check_line);
|
||||
|
||||
while (line.is_empty() && check_line > -1) {
|
||||
--check_line;
|
||||
|
||||
line = text_editor->get_line(check_line);
|
||||
}
|
||||
|
||||
++check_line;
|
||||
|
||||
if (check_line < final_line) {
|
||||
text_editor->begin_complex_operation();
|
||||
|
||||
text_editor->remove_text(check_line, 0, final_line, 0);
|
||||
|
||||
text_editor->merge_overlapping_carets();
|
||||
text_editor->end_complex_operation();
|
||||
text_editor->queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::insert_final_newline() {
|
||||
int final_line = text_editor->get_line_count() - 1;
|
||||
String line = text_editor->get_line(final_line);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue