diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 20525dd028e..4ec2a3c3914 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1071,7 +1071,8 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - text_editor->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); + text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type") == "Tabs" ? 0 : 1); + text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_numbers_zero_padded")); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index f1daf05432c..35373eb8158 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -529,8 +529,11 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { set("text_editor/highlighting/highlight_all_occurrences", true); set("text_editor/cursor/scroll_past_end_of_file", false); - set("text_editor/indent/tab_size", 4); - hints["text_editor/indent/tab_size"] = PropertyInfo(Variant::INT, "text_editor/indent/tab_size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + set("text_editor/indent/type", 0); + hints["text_editor/indent/type"] = PropertyInfo(Variant::STRING, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); + set("text_editor/indent/size", 4); + hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + set("text_editor/indent/convert_indent_on_save", false); set("text_editor/indent/draw_tabs", true); set("text_editor/line_numbers/show_line_numbers", true); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index c94ab706bc2..48a2897e7af 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -530,6 +530,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) { if (trim_trailing_whitespace_on_save) { se->trim_trailing_whitespace(); } + + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + editor->save_resource(script); se->tag_saved_version(); } @@ -795,12 +804,28 @@ void ScriptEditor::_menu_option(int p_option) { if (trim_trailing_whitespace_on_save) current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->save_resource(current->get_edited_script()); } break; case FILE_SAVE_AS: { current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->push_item(current->get_edited_script()->cast_to()); editor->save_resource_as(current->get_edited_script()); @@ -1484,6 +1509,14 @@ void ScriptEditor::save_all_scripts() { se->trim_trailing_whitespace(); } + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + Ref