Skip to content

Commit 80d1459

Browse files
committed
Merge pull request godotengine#102193 from MartinDelille/shader-focus
Focus shader text editor when opened with quick open dialog
2 parents 09bc1ca + 9e190d1 commit 80d1459

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
@@ -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

206206
bool ShaderEditorPlugin::handles(Object *p_object) const {
@@ -226,6 +226,8 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_sha
226226
}
227227

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

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

798808
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
@@ -95,6 +95,7 @@ class ShaderEditorPlugin : public EditorPlugin {
9595
ShaderCreateDialog *shader_create_dialog = nullptr;
9696

9797
float text_shader_zoom_factor = 1.0f;
98+
bool restoring_layout = false;
9899

99100
Ref<Resource> _get_current_shader();
100101
void _update_shader_list();
@@ -124,7 +125,7 @@ class ShaderEditorPlugin : public EditorPlugin {
124125
void _set_text_shader_zoom_factor(float p_zoom_factor);
125126
void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;
126127

127-
void _switch_to_editor(ShaderEditor *p_editor);
128+
void _switch_to_editor(ShaderEditor *p_editor, bool p_focus = false);
128129

129130
protected:
130131
void _notification(int p_what);

0 commit comments

Comments
 (0)