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

Code before:
	callable_mp(this, &SceneTreeDock::_update_script_button).call_deferred();
}

void SceneTreeDock::_selection_changed() {
	int selection_size = editor_selection->get_selection().size();
	if (selection_size > 1) {
		//automatically turn on multi-edit
		_tool_selected(TOOL_MULTI_EDIT);
	} else if (selection_size == 1) {
		Node *node = ObjectDB::get_instance<Node>(editor_selection->get_selection().begin()->key);
		if (node) {
			_handle_select(node);
		}
	} else if (selection_size == 0) {
		_push_item(nullptr);
	}

	// Untrack script changes in previously selected nodes.
	clear_previous_node_selection();

	// Track script changes in newly selected nodes.
	node_previous_selection.reserve(editor_selection->get_selection().size());
	for (const KeyValue<ObjectID, Object *> &E : editor_selection->get_selection()) {
		Node *node = ObjectDB::get_instance<Node>(E.key);
		if (node) {
			node_previous_selection.push_back(node->get_instance_id());
			node->connect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
		}
	}
	_queue_update_script_button();
}

Node *SceneTreeDock::_do_create(Node *p_parent) {
	Variant c = create_dialog->instantiate_selected();
	Node *child = Object::cast_to<Node>(c);
	ERR_FAIL_NULL_V(child, nullptr);

	String new_name = p_parent->validate_child_name(child);
	if (GLOBAL_GET("editor/naming/node_name_casing").operator int() != NAME_CASING_PASCAL_CASE) {
		new_name = adjust_name_casing(new_name);
	}
	child->set_name(new_name);

	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action_for_history(TTR("Create Node"), editor_data->get_current_edited_scene_history_id());

	if (edited_scene) {
		undo_redo->add_do_method(p_parent, "add_child", child, true);
		undo_redo->add_do_method(child, "set_owner", edited_scene);
		undo_redo->add_do_reference(child);
		undo_redo->add_undo_method(p_parent, "remove_child", child);

Review comment (suggestion):
```suggestion
			node_previous_selection.push_back(E.key);
```

Code after:
	if (update_script_button_queued) {
		return;
	}
	update_script_button_queued = true;
	callable_mp(this, &SceneTreeDock::_update_script_button).call_deferred();
}

void SceneTreeDock::_selection_changed() {
	int selection_size = editor_selection->get_selection().size();
	if (selection_size > 1) {
		//automatically turn on multi-edit
		_tool_selected(TOOL_MULTI_EDIT);
	} else if (selection_size == 1) {
		Node *node = ObjectDB::get_instance<Node>(editor_selection->get_selection().begin()->key);
		if (node) {
			_handle_select(node);
		}
	} else if (selection_size == 0) {
		_push_item(nullptr);
	}

	// Untrack script changes in previously selected nodes.
	clear_previous_node_selection();

	// Track script changes in newly selected nodes.
	node_previous_selection.reserve(editor_selection->get_selection().size());
	for (const KeyValue<ObjectID, Object *> &E : editor_selection->get_selection()) {
		Node *node = ObjectDB::get_instance<Node>(E.key);
		if (node) {
			node_previous_selection.push_back(E.key);
			node->connect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
		}
	}
	_queue_update_script_button();
}

Node *SceneTreeDock::_do_create(Node *p_parent) {
	Variant c = create_dialog->instantiate_selected();
	Node *child = Object::cast_to<Node>(c);
	ERR_FAIL_NULL_V(child, nullptr);

	String new_name = p_parent->validate_child_name(child);
	if (GLOBAL_GET("editor/naming/node_name_casing").operator int() != NAME_CASING_PASCAL_CASE) {
		new_name = adjust_name_casing(new_name);
	}
	child->set_name(new_name);

	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action_for_history(TTR("Create Node"), editor_data->get_current_edited_scene_history_id());

	if (edited_scene) {