summaryrefslogtreecommitdiffstats
path: root/editor/code_editor.cpp
diff options
context:
space:
mode:
authorAiden Storey <git@storey.dev>2024-01-12 00:32:13 -0500
committerAiden Storey <git@storey.dev>2024-05-02 22:57:34 -0400
commitb4c1634b52f619ca8987b67ecee2640310781aa7 (patch)
tree592faafc74fefb2dfb3e4a5ff4d8e63fb2e52513 /editor/code_editor.cpp
parentd4f726f3ef21cef3e7936b2c9770cdac6478b8ee (diff)
downloadredot-engine-b4c1634b52f619ca8987b67ecee2640310781aa7.tar.gz
Implement trim_final_newlines functionality
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r--editor/code_editor.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index cfeb495690..1d47658266 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -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);