diff --git a/core/object/script_language.h b/core/object/script_language.h index 3ddfbb3e7d35..cc02d23a4351 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -363,6 +363,7 @@ class ScriptLanguage : public Object { virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; } + virtual String format_code(const String &p_code) { return p_code; } virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const = 0; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) = 0; virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) {} diff --git a/editor/plugins/SCsub b/editor/plugins/SCsub index 4b6abf18f946..1ca3ba8409f4 100644 --- a/editor/plugins/SCsub +++ b/editor/plugins/SCsub @@ -4,5 +4,8 @@ Import("env") env.add_source_files(env.editor_sources, "*.cpp") +if env["tests"]: + env.Append(CPPDEFINES=["TESTS_ENABLED"]) + SConscript("gizmos/SCsub") SConscript("tiles/SCsub") diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 8e82d606052e..0e1cf87b5809 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -175,6 +175,7 @@ class ScriptEditorBase : public VBoxContainer { virtual void clear_executing_line() = 0; virtual void trim_trailing_whitespace() = 0; virtual void trim_final_newlines() = 0; + virtual void format_code() = 0; virtual void insert_final_newline() = 0; virtual void convert_indent() = 0; virtual void ensure_focus() = 0; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 7e8fba8b9ecc..7cd532faa40a 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -438,6 +438,42 @@ void ScriptTextEditor::trim_trailing_whitespace() { code_editor->trim_trailing_whitespace(); } +void ScriptTextEditor::format_code() { +#ifdef TESTS_ENABLED + CodeEdit *tx = code_editor->get_text_editor(); + const String original = tx->get_text(); + Ref