Skip to content

Commit e761c71

Browse files
committed
Focus shader text editor when opened with quick open dialog
1 parent 0fdbf05 commit e761c71

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

editor/shader/shader_editor_plugin.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -778,7 +778,7 @@ void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_sha
778778
}
779779
}
780780

781-
void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
781+
void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor, bool p_focus) {
782782
ERR_FAIL_NULL(p_editor);
783783
if (file_menu->get_parent() != nullptr) {
784784
file_menu->get_parent()->remove_child(file_menu);
@@ -788,6 +788,12 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
788788
}
789789
empty_menu->set_visible(false);
790790
p_editor->use_menu_bar_items(file_menu, make_floating);
791+
if (p_focus) {
792+
TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(p_editor);
793+
if (text_shader_editor) {
794+
text_shader_editor->get_code_editor()->get_text_editor()->grab_focus();
795+
}
796+
}
791797
}
792798

793799
void ShaderEditorPlugin::_file_removed(const String &p_removed_file) {

editor/shader/shader_editor_plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ShaderEditorPlugin : public EditorPlugin {
127127
void _set_text_shader_zoom_factor(float p_zoom_factor);
128128
void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;
129129

130-
void _switch_to_editor(ShaderEditor *p_editor);
130+
void _switch_to_editor(ShaderEditor *p_editor, bool p_focus = false);
131131

132132
protected:
133133
void _notification(int p_what);

0 commit comments

Comments
 (0)