Implement trim_final_newlines functionality

This commit is contained in:
Aiden Storey 2024-01-12 00:32:13 -05:00
parent d4f726f3ef
commit b4c1634b52
13 changed files with 99 additions and 4 deletions

View file

@ -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);