Skip to content

Commit 9e190d1

Browse files
committed
Focus shader text editor when opened with quick open dialog
1 parent eb3d6d8 commit 9e190d1

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

editor/shader/shader_editor_plugin.cpp

Lines changed: 14 additions & 4 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
}
@@ -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

201201
bool ShaderEditorPlugin::handles(Object *p_object) const {
@@ -221,6 +221,8 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_sha
221221
}
222222

223223
void 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

268272
void 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

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

editor/shader/shader_editor_plugin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class ShaderEditorPlugin : public EditorPlugin {
9898
ShaderCreateDialog *shader_create_dialog = nullptr;
9999

100100
float text_shader_zoom_factor = 1.0f;
101+
bool restoring_layout = false;
101102

102103
Ref<Resource> _get_current_shader();
103104
void _update_shader_list();
@@ -127,7 +128,7 @@ class ShaderEditorPlugin : public EditorPlugin {
127128
void _set_text_shader_zoom_factor(float p_zoom_factor);
128129
void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;
129130

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

132133
protected:
133134
void _notification(int p_what);

0 commit comments

Comments
 (0)