diff options
-rw-r--r-- | editor/code_editor.cpp | 18 | ||||
-rw-r--r-- | editor/code_editor.h | 1 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 11 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.h | 1 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.h | 1 | ||||
-rw-r--r-- | editor/plugins/text_editor.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/text_editor.h | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 3 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 1 |
10 files changed, 46 insertions, 1 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 33adb33c8c..4a440510db 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -804,6 +804,24 @@ void CodeTextEditor::trim_trailing_whitespace() { } } +void CodeTextEditor::insert_final_newline() { + int final_line = text_editor->get_line_count() - 1; + + String line = text_editor->get_line(final_line); + + //length 0 means it's already an empty line, + //no need to add a newline + if (line.length() > 0 && !line.ends_with("\n")) { + text_editor->begin_complex_operation(); + + line += "\n"; + text_editor->set_line(final_line, line); + + text_editor->end_complex_operation(); + text_editor->update(); + } +} + void CodeTextEditor::convert_indent_to_spaces() { int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); String indent = ""; diff --git a/editor/code_editor.h b/editor/code_editor.h index 5c6b54ae44..cf97f30b72 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -195,6 +195,7 @@ protected: public: void trim_trailing_whitespace(); + void insert_final_newline(); void convert_indent_to_spaces(); void convert_indent_to_tabs(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 641c387c64..f45e6a2c9a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -723,6 +723,8 @@ void ScriptEditor::_resave_scripts(const String &p_str) { se->trim_trailing_whitespace(); } + se->insert_final_newline(); + if (convert_indent_on_save) { if (use_space_indentation) { se->convert_indent_to_spaces(); @@ -1078,6 +1080,8 @@ void ScriptEditor::_menu_option(int p_option) { if (trim_trailing_whitespace_on_save) current->trim_trailing_whitespace(); + current->insert_final_newline(); + if (convert_indent_on_save) { if (use_space_indentation) { current->convert_indent_to_spaces(); @@ -1097,7 +1101,10 @@ void ScriptEditor::_menu_option(int p_option) { } break; case FILE_SAVE_AS: { - current->trim_trailing_whitespace(); + if (trim_trailing_whitespace_on_save) + current->trim_trailing_whitespace(); + + current->insert_final_newline(); if (convert_indent_on_save) { if (use_space_indentation) { @@ -2121,6 +2128,8 @@ void ScriptEditor::save_all_scripts() { se->trim_trailing_whitespace(); } + se->insert_final_newline(); + if (!se->is_unsaved()) continue; diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 683fa881f8..fae98d6ec8 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -99,6 +99,7 @@ public: virtual void set_executing_line(int p_line) = 0; virtual void clear_executing_line() = 0; virtual void trim_trailing_whitespace() = 0; + virtual void insert_final_newline() = 0; virtual void convert_indent_to_spaces() = 0; virtual void convert_indent_to_tabs() = 0; virtual void ensure_focus() = 0; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1fe4ac1372..79867f40ca 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -457,6 +457,11 @@ void ScriptTextEditor::trim_trailing_whitespace() { code_editor->trim_trailing_whitespace(); } +void ScriptTextEditor::insert_final_newline() { + + code_editor->insert_final_newline(); +} + void ScriptTextEditor::convert_indent_to_spaces() { code_editor->convert_indent_to_spaces(); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index bdfdf18d45..7f5b6c065d 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -194,6 +194,7 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void ensure_focus(); virtual void trim_trailing_whitespace(); + virtual void insert_final_newline(); virtual void convert_indent_to_spaces(); virtual void convert_indent_to_tabs(); virtual void tag_saved_version(); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index a0f3c253d1..d036d7e965 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -251,6 +251,11 @@ void TextEditor::trim_trailing_whitespace() { code_editor->trim_trailing_whitespace(); } +void TextEditor::insert_final_newline() { + + code_editor->insert_final_newline(); +} + void TextEditor::convert_indent_to_spaces() { code_editor->convert_indent_to_spaces(); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 2da7474793..e06d816177 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -130,6 +130,7 @@ public: virtual void set_executing_line(int p_line); virtual void clear_executing_line(); virtual void trim_trailing_whitespace(); + virtual void insert_final_newline(); virtual void convert_indent_to_spaces(); virtual void convert_indent_to_tabs(); virtual void ensure_focus(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index aad6e95845..f84f2c90cd 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2111,6 +2111,9 @@ void VisualScriptEditor::clear_executing_line() { void VisualScriptEditor::trim_trailing_whitespace() { } +void VisualScriptEditor::insert_final_newline() { +} + void VisualScriptEditor::convert_indent_to_spaces() { } diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 3d3a49f672..6072e77342 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -266,6 +266,7 @@ public: virtual void set_executing_line(int p_line); virtual void clear_executing_line(); virtual void trim_trailing_whitespace(); + virtual void insert_final_newline(); virtual void convert_indent_to_spaces(); virtual void convert_indent_to_tabs(); virtual void ensure_focus(); |