@@ -146,7 +146,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
146146 if (edited_shaders[i].shader_inc .ptr () == shader_include) {
147147 shader_tabs->set_current_tab (i);
148148 shader_list->select (i);
149- _switch_to_editor (edited_shaders[i].shader_editor );
149+ _switch_to_editor (edited_shaders[i].shader_editor , true );
150150 return ;
151151 }
152152 }
@@ -162,7 +162,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
162162 if (edited_shaders[i].shader .ptr () == shader) {
163163 shader_tabs->set_current_tab (i);
164164 shader_list->select (i);
165- _switch_to_editor (edited_shaders[i].shader_editor );
165+ _switch_to_editor (edited_shaders[i].shader_editor , true );
166166 return ;
167167 }
168168 }
@@ -195,7 +195,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
195195 shader_tabs->set_current_tab (shader_tabs->get_tab_count () - 1 );
196196 edited_shaders.push_back (es);
197197 _update_shader_list ();
198- _switch_to_editor (es.shader_editor );
198+ _switch_to_editor (es.shader_editor , !restoring_layout );
199199}
200200
201201bool ShaderEditorPlugin::handles (Object *p_object) const {
@@ -221,6 +221,8 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_sha
221221}
222222
223223void ShaderEditorPlugin::set_window_layout (Ref<ConfigFile> p_layout) {
224+ restoring_layout = true ;
225+
224226 if (EDITOR_GET (" interface/multi_window/restore_windows_on_load" ) && window_wrapper->is_window_available () && p_layout->has_section_key (" ShaderEditor" , " window_rect" )) {
225227 window_wrapper->restore_window_from_saved_position (
226228 p_layout->get_value (" ShaderEditor" , " window_rect" , Rect2i ()),
@@ -263,6 +265,8 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
263265 _shader_selected (selected_shader_idx, false );
264266
265267 _set_text_shader_zoom_factor (p_layout->get_value (" ShaderEditor" , " text_shader_zoom_factor" , 1 .0f ));
268+
269+ restoring_layout = false ;
266270}
267271
268272void ShaderEditorPlugin::get_window_layout (Ref<ConfigFile> p_layout) {
@@ -778,7 +782,7 @@ void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_sha
778782 }
779783}
780784
781- void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor) {
785+ void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor, bool p_focus ) {
782786 ERR_FAIL_NULL (p_editor);
783787 if (file_menu->get_parent () != nullptr ) {
784788 file_menu->get_parent ()->remove_child (file_menu);
@@ -788,6 +792,12 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
788792 }
789793 empty_menu->set_visible (false );
790794 p_editor->use_menu_bar_items (file_menu, make_floating);
795+ if (p_focus) {
796+ TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(p_editor);
797+ if (text_shader_editor) {
798+ text_shader_editor->get_code_editor ()->get_text_editor ()->grab_focus ();
799+ }
800+ }
791801}
792802
793803void ShaderEditorPlugin::_file_removed (const String &p_removed_file) {
0 commit comments