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

Code before:
	// Pack first, so it stores diffs to previous version of saved scene.
	Error err = pscene->pack(edited_scene[p_idx].root);
	ERR_FAIL_COND_V(err != OK, false);
	ep.step(TTR("Updating scene..."), 1);
	Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN);
	ERR_FAIL_NULL_V(new_scene, false);

	// Transfer selection.
	List<Node *> new_selection;
	for (const Node *E : edited_scene.write[p_idx].selection) {
		NodePath p = edited_scene[p_idx].root->get_path_to(E);
		Node *new_node = new_scene->get_node(p);
		if (new_node) {
			new_selection.push_back(new_node);
		}
	}

	new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path());
	Node *old_root = edited_scene[p_idx].root;
	EditorNode::get_singleton()->set_edited_scene(new_scene);
	memdelete(old_root);
	edited_scene.write[p_idx].selection = new_selection;

	if (need_mark_unsaved) {
		EditorUndoRedoManager::get_singleton()->clear_history();
		EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(get_current_edited_scene_history_id());
	}
	return true;
}

int EditorData::get_edited_scene() const {
	return current_edited_scene;
}

int EditorData::get_edited_scene_from_path(const String &p_path) const {
	for (int i = 0; i < edited_scene.size(); i++) {
		if (edited_scene[i].path == p_path) {
			return i;
		}
	}

	return -1;
}

void EditorData::set_edited_scene(int p_idx) {
	ERR_FAIL_INDEX(p_idx, edited_scene.size());
	current_edited_scene = p_idx;
}

Node *EditorData::get_edited_scene_root(int p_idx) {
	if (p_idx < 0) {

Review comment (suggestion):
You don't need to clear the whole history.
```suggestion
		EditorUndoRedoManager::get_singleton()->clear_history(get_scene_history_id(p_idx));
```

Code after:
	// Pack first, so it stores diffs to previous version of saved scene.
	Error err = pscene->pack(edited_scene[p_idx].root);
	ERR_FAIL_COND_V(err != OK, false);
	ep.step(TTR("Updating scene..."), 1);
	Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN);
	ERR_FAIL_NULL_V(new_scene, false);

	// Transfer selection.
	List<Node *> new_selection;
	for (const Node *E : edited_scene.write[p_idx].selection) {
		NodePath p = edited_scene[p_idx].root->get_path_to(E);
		Node *new_node = new_scene->get_node(p);
		if (new_node) {
			new_selection.push_back(new_node);
		}
	}

	new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path());
	Node *old_root = edited_scene[p_idx].root;
	EditorNode::get_singleton()->set_edited_scene(new_scene);
	memdelete(old_root);
	edited_scene.write[p_idx].selection = new_selection;

	if (p_mark_unsaved) {
		EditorUndoRedoManager::get_singleton()->clear_history(get_scene_history_id(p_idx));
	}
	return true;
}

int EditorData::get_edited_scene() const {
	return current_edited_scene;
}

int EditorData::get_edited_scene_from_path(const String &p_path) const {
	for (int i = 0; i < edited_scene.size(); i++) {
		if (edited_scene[i].path == p_path) {
			return i;
		}
	}

	return -1;
}

void EditorData::set_edited_scene(int p_idx) {
	ERR_FAIL_INDEX(p_idx, edited_scene.size());
	current_edited_scene = p_idx;
}

Node *EditorData::get_edited_scene_root(int p_idx) {
	if (p_idx < 0) {
		ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), nullptr);