diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 7e39c4c6544..63514f8b82b 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2447,15 +2447,24 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { Node *scene = editor_data.get_edited_scene_root(scene_idx); if (!scene) { - int saved = _save_external_resources(); - String err_text; - if (saved > 0) { - err_text = vformat(TTR("Saved %s modified resource(s)."), itos(saved)); - } else { - err_text = TTR("A root node is required to save the scene."); + if (p_option == FILE_SAVE_SCENE) { + // Pressing Ctrl + S saves the current script if a scene is currently open, but it won't if the scene has no root node. + // Work around this by explicitly saving the script in this case (similar to pressing Ctrl + Alt + S). + ScriptEditor::get_singleton()->save_current_script(); + } + + const int saved = _save_external_resources(); + if (saved > 0) { + show_accept( + vformat(TTR("The current scene has no root node, but %d modified external resource(s) were saved anyway."), saved), + TTR("OK")); + } else if (p_option == FILE_SAVE_AS_SCENE) { + // Don't show this dialog when pressing Ctrl + S to avoid interfering with script saving. + show_accept( + TTR("A root node is required to save the scene. You can add a root node using the Scene tree dock."), + TTR("OK")); } - show_accept(err_text, TTR("OK")); break; } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index adfeead33b6..8c4c5a34619 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -703,7 +703,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { // Do not try to save internal scripts, but prompt to save in-memory // scripts which are not saved to disk yet (have empty path). if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { - _save_current_script(); + save_current_script(); } } if (script.is_valid()) { @@ -1101,59 +1101,6 @@ bool ScriptEditor::is_scripts_panel_toggled() { return list_split->is_visible(); } -void ScriptEditor::_save_current_script() { - ScriptEditorBase *current = _get_current_editor(); - - if (_test_script_times_on_disk()) { - return; - } - - 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(); - } else { - current->convert_indent_to_tabs(); - } - } - - RES resource = current->get_edited_resource(); - Ref text_file = resource; - Ref