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

Code before:
}

void EditorSelection::remove_node(Node *p_node) {
	ERR_FAIL_NULL(p_node);
	ObjectID nid = p_node->get_instance_id();
	if (!selection.has(nid)) {
		return;
	}

	changed = true;
	node_list_changed = true;
	Object *meta = selection[nid];
	if (meta) {
		memdelete(meta);
	}
	selection.erase(nid);

	p_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &EditorSelection::_node_removed));
}

bool EditorSelection::is_selected(Node *p_node) const {
	if (!p_node) {
		return false;
	}
	ObjectID nid = p_node->get_instance_id();
	return selection.has(nid);
}

void EditorSelection::_bind_methods() {
	ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
	ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
	ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
	ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
	ClassDB::bind_method(D_METHOD("get_top_selected_nodes"), &EditorSelection::get_top_selected_nodes);
#ifndef DISABLE_DEPRECATED
	ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::get_top_selected_nodes);
#endif // DISABLE_DEPRECATED
	ADD_SIGNAL(MethodInfo("selection_changed"));
}

void EditorSelection::add_editor_plugin(Object *p_object) {
	editor_plugins.push_back(p_object);
}

void EditorSelection::_update_node_list() {
	if (!node_list_changed) {
		return;
	}

	top_selected_node_list.clear();


Review comment (suggestion):
```suggestion
	return selection.has(p_node->get_instance_id());
```

Code after:
		return;
	}

	changed = true;
	node_list_changed = true;
	Object *meta = nullptr;
	for (Object *E : editor_plugins) {
		meta = E->call("_get_editor_data", p_node);
		if (meta) {
			break;
		}
	}
	selection[nid] = meta;

	p_node->connect(SceneStringName(tree_exiting), callable_mp(this, &EditorSelection::_node_removed).bind(p_node), CONNECT_ONE_SHOT);
}

void EditorSelection::remove_node(Node *p_node) {
	ERR_FAIL_NULL(p_node);
	ObjectID nid = p_node->get_instance_id();
	if (!selection.has(nid)) {
		return;
	}

	changed = true;
	node_list_changed = true;
	Object *meta = selection[nid];
	memdelete_notnull(meta);
	selection.erase(nid);

	p_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &EditorSelection::_node_removed));
}

bool EditorSelection::is_selected(Node *p_node) const {
	if (!p_node) {
		return false;
	}
	return selection.has(p_node->get_instance_id());
}

void EditorSelection::_bind_methods() {
	ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
	ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
	ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
	ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
	ClassDB::bind_method(D_METHOD("get_top_selected_nodes"), &EditorSelection::get_top_selected_nodes);
#ifndef DISABLE_DEPRECATED
	ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::get_top_selected_nodes);
#endif // DISABLE_DEPRECATED
	ADD_SIGNAL(MethodInfo("selection_changed"));
}