Editor: Set initial focus for screen reader users

When accessibility is enabled, set initial focus on editor startup:
- If the Scene dock is the active tab, focus the scene tree
- Otherwise, focus the dock tab bar so the user can switch tabs

This gives screen reader users a predictable starting point for
keyboard navigation without overriding their saved dock layout.
This commit is contained in:
Nolan Darilek
2025-12-02 16:43:15 -05:00
parent 1559ab34c6
commit f4aeec3a1a

View File

@@ -1443,6 +1443,20 @@ void EditorNode::_sources_changed(bool p_exist) {
if (!singleton->cmdline_mode) {
EditorResourcePreview::get_singleton()->start();
}
// Set initial focus for screen reader users.
if (get_tree()->is_accessibility_enabled()) {
if (SceneTreeDock::get_singleton()->is_visible_in_tree()) {
SceneTreeDock::get_singleton()->get_tree_editor()->get_scene_tree()->grab_focus();
} else {
TabContainer *tab_container = EditorDockManager::get_singleton()->get_dock_tab_container(SceneTreeDock::get_singleton());
if (tab_container) {
// Another tab is active (e.g., Import) - focus the tab bar so user can switch.
tab_container->get_tab_bar()->grab_focus();
}
}
}
get_tree()->create_timer(1.0f)->connect("timeout", callable_mp(this, &EditorNode::_remove_lock_file));
}
}