@@ -147,7 +147,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
147147 if (edited_shaders[i].shader_inc .ptr () == shader_include) {
148148 shader_tabs->set_current_tab (i);
149149 shader_list->select (i);
150- _switch_to_editor (edited_shaders[i].shader_editor );
150+ _switch_to_editor (edited_shaders[i].shader_editor , true );
151151 return ;
152152 }
153153 }
@@ -167,7 +167,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
167167 if (edited_shaders[i].shader .ptr () == shader) {
168168 shader_tabs->set_current_tab (i);
169169 shader_list->select (i);
170- _switch_to_editor (edited_shaders[i].shader_editor );
170+ _switch_to_editor (edited_shaders[i].shader_editor , true );
171171 return ;
172172 }
173173 }
@@ -200,7 +200,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
200200 shader_tabs->set_current_tab (shader_tabs->get_tab_count () - 1 );
201201 edited_shaders.push_back (es);
202202 _update_shader_list ();
203- _switch_to_editor (es.shader_editor );
203+ _switch_to_editor (es.shader_editor , !restoring_layout );
204204}
205205
206206bool ShaderEditorPlugin::handles (Object *p_object) const {
@@ -226,6 +226,8 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_sha
226226}
227227
228228void ShaderEditorPlugin::set_window_layout (Ref<ConfigFile> p_layout) {
229+ restoring_layout = true ;
230+
229231 if (EDITOR_GET (" interface/multi_window/restore_windows_on_load" ) && window_wrapper->is_window_available () && p_layout->has_section_key (" ShaderEditor" , " window_rect" )) {
230232 window_wrapper->restore_window_from_saved_position (
231233 p_layout->get_value (" ShaderEditor" , " window_rect" , Rect2i ()),
@@ -268,6 +270,8 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
268270 _shader_selected (selected_shader_idx, false );
269271
270272 _set_text_shader_zoom_factor (p_layout->get_value (" ShaderEditor" , " text_shader_zoom_factor" , 1 .0f ));
273+
274+ restoring_layout = false ;
271275}
272276
273277void ShaderEditorPlugin::get_window_layout (Ref<ConfigFile> p_layout) {
@@ -783,7 +787,7 @@ void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_sha
783787 }
784788}
785789
786- void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor) {
790+ void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor, bool p_focus ) {
787791 ERR_FAIL_NULL (p_editor);
788792 if (file_menu->get_parent () != nullptr ) {
789793 file_menu->get_parent ()->remove_child (file_menu);
@@ -793,6 +797,12 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
793797 }
794798 empty_menu->set_visible (false );
795799 p_editor->use_menu_bar_items (file_menu, make_floating);
800+ if (p_focus) {
801+ TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(p_editor);
802+ if (text_shader_editor) {
803+ text_shader_editor->get_code_editor ()->get_text_editor ()->grab_focus ();
804+ }
805+ }
796806}
797807
798808void ShaderEditorPlugin::_file_removed (const String &p_removed_file) {
0 commit comments