Repository: godotengine/godot
File: editor/editor_node.cpp (C++)

Code before:

		if (!defer_load_scene.is_empty()) {
			OS::get_singleton()->benchmark_begin_measure("Editor", "Load Scene");

			load_scene(defer_load_scene);
			defer_load_scene = "";

			OS::get_singleton()->benchmark_end_measure("Editor", "Load Scene");
			OS::get_singleton()->benchmark_dump();
		}

		// Start preview thread now that it's safe.
		if (!singleton->cmdline_mode) {
			EditorResourcePreview::get_singleton()->start();
		}

		// Set initial focus for screen reader users.
		if (get_tree()->is_accessibility_enabled()) {
			TabContainer *tab_container = EditorDockManager::get_singleton()->get_dock_tab_container(SceneTreeDock::get_singleton());
			if (tab_container && tab_container->get_current_tab_control() == SceneTreeDock::get_singleton()) {
				// Scene dock is active - focus the scene tree.
				SceneTreeDock::get_singleton()->get_tree_editor()->get_scene_tree()->grab_focus();
			} else 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));
	}
}

void EditorNode::_remove_lock_file() {
	OS::get_singleton()->remove_lock_file();
}

void EditorNode::_scan_external_changes() {
	disk_changed_list->clear();
	TreeItem *r = disk_changed_list->create_item();
	disk_changed_list->set_hide_root(true);
	bool need_reload = false;

	disk_changed_scenes.clear();
	disk_changed_project = false;

	// Check if any edited scene has changed.
	for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
		Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);

		const String scene_path = editor_data.get_scene_path(i);


Review comment (suggestion):
This can be simplified to (not tested)

```suggestion
			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();
				}
			}
```
Note that if the Scene dock is missing for whatever reason (like closed or something), the editor will still have no focus. It's unlikely to happen though.

Code after:

		// Reload the global shader variables, but this time
		// loading textures, as they are now properly imported.
		RenderingServer::get_singleton()->global_shader_parameters_load_settings(true);

		_load_editor_layout();

		if (!defer_load_scene.is_empty()) {
			OS::get_singleton()->benchmark_begin_measure("Editor", "Load Scene");

			load_scene(defer_load_scene);
			defer_load_scene = "";

			OS::get_singleton()->benchmark_end_measure("Editor", "Load Scene");
			OS::get_singleton()->benchmark_dump();
		}

		// Start preview thread now that it's safe.
		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));
	}
}

void EditorNode::_remove_lock_file() {
	OS::get_singleton()->remove_lock_file();
}

void EditorNode::_scan_external_changes() {
	disk_changed_list->clear();
	TreeItem *r = disk_changed_list->create_item();
	disk_changed_list->set_hide_root(true);
	bool need_reload = false;

	disk_changed_scenes.clear();
	disk_changed_project = false;