diff --git a/editor/shader/shader_editor_plugin.cpp b/editor/shader/shader_editor_plugin.cpp index 12d4ef41171..9dbb65796a8 100644 --- a/editor/shader/shader_editor_plugin.cpp +++ b/editor/shader/shader_editor_plugin.cpp @@ -146,7 +146,7 @@ void ShaderEditorPlugin::edit(Object *p_object) { if (edited_shaders[i].shader_inc.ptr() == shader_include) { shader_tabs->set_current_tab(i); shader_list->select(i); - _switch_to_editor(edited_shaders[i].shader_editor); + _switch_to_editor(edited_shaders[i].shader_editor, true); return; } } @@ -162,7 +162,7 @@ void ShaderEditorPlugin::edit(Object *p_object) { if (edited_shaders[i].shader.ptr() == shader) { shader_tabs->set_current_tab(i); shader_list->select(i); - _switch_to_editor(edited_shaders[i].shader_editor); + _switch_to_editor(edited_shaders[i].shader_editor, true); return; } } @@ -195,7 +195,7 @@ void ShaderEditorPlugin::edit(Object *p_object) { shader_tabs->set_current_tab(shader_tabs->get_tab_count() - 1); edited_shaders.push_back(es); _update_shader_list(); - _switch_to_editor(es.shader_editor); + _switch_to_editor(es.shader_editor, !restoring_layout); } bool ShaderEditorPlugin::handles(Object *p_object) const { @@ -221,6 +221,8 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref &p_for_sha } void ShaderEditorPlugin::set_window_layout(Ref p_layout) { + restoring_layout = true; + if (EDITOR_GET("interface/multi_window/restore_windows_on_load") && window_wrapper->is_window_available() && p_layout->has_section_key("ShaderEditor", "window_rect")) { window_wrapper->restore_window_from_saved_position( p_layout->get_value("ShaderEditor", "window_rect", Rect2i()), @@ -263,6 +265,8 @@ void ShaderEditorPlugin::set_window_layout(Ref p_layout) { _shader_selected(selected_shader_idx, false); _set_text_shader_zoom_factor(p_layout->get_value("ShaderEditor", "text_shader_zoom_factor", 1.0f)); + + restoring_layout = false; } void ShaderEditorPlugin::get_window_layout(Ref p_layout) { @@ -778,7 +782,7 @@ void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_sha } } -void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) { +void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor, bool p_focus) { ERR_FAIL_NULL(p_editor); if (file_menu->get_parent() != nullptr) { file_menu->get_parent()->remove_child(file_menu); @@ -788,6 +792,12 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) { } empty_menu->set_visible(false); p_editor->use_menu_bar_items(file_menu, make_floating); + if (p_focus) { + TextShaderEditor *text_shader_editor = Object::cast_to(p_editor); + if (text_shader_editor) { + text_shader_editor->get_code_editor()->get_text_editor()->grab_focus(); + } + } } void ShaderEditorPlugin::_file_removed(const String &p_removed_file) { diff --git a/editor/shader/shader_editor_plugin.h b/editor/shader/shader_editor_plugin.h index 41df5b3a873..daab8036119 100644 --- a/editor/shader/shader_editor_plugin.h +++ b/editor/shader/shader_editor_plugin.h @@ -98,6 +98,7 @@ class ShaderEditorPlugin : public EditorPlugin { ShaderCreateDialog *shader_create_dialog = nullptr; float text_shader_zoom_factor = 1.0f; + bool restoring_layout = false; Ref _get_current_shader(); void _update_shader_list(); @@ -127,7 +128,7 @@ class ShaderEditorPlugin : public EditorPlugin { void _set_text_shader_zoom_factor(float p_zoom_factor); void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const; - void _switch_to_editor(ShaderEditor *p_editor); + void _switch_to_editor(ShaderEditor *p_editor, bool p_focus = false); protected: void _notification(int p_what);