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

Code before:
				break; // Stop testing base types as soon as we get a match.
			}
		}
	}
}

void QuickOpenResultContainer::set_query_and_update(const String &p_query) {
	query = p_query;
	update_results();
}

Vector<ResourceUID::ID> *QuickOpenResultContainer::_get_history() {
	if (base_types.size() != 1) {
		return nullptr;
	}

	StringName type = base_types[0];

	Vector<ResourceUID::ID> *history = selected_history.getptr(type);

	if (!history) {
		return nullptr;
	}

	bool history_changed = false;
	Vector<ResourceUID::ID> clean_history;

	for (const ResourceUID::ID &uid : *history) {
		if (ResourceUID::get_singleton()->has_id(uid)) {
			clean_history.push_back(uid);
		} else {
			history_changed = true;
		}
	}

	if (clean_history.is_empty()) {
		selected_history.erase(type);
		return nullptr;
	}

	if (history_changed) {
		*history = clean_history;
	}

	return history;
}

QuickOpenResultCandidate QuickOpenResultCandidate::from_uid(const ResourceUID::ID &p_uid, bool &success) {
	if (p_uid == ResourceUID::INVALID_ID || !ResourceUID::get_singleton()->has_id(p_uid)) {
		success = false;
		return QuickOpenResultCandidate();

Review comment (suggestion):
Performing the cleanup in this method means that the history may get validated multiple times when dialog is opened. It's unnecessary. It's only useful when a file is deleted externally while the dialog is open, which is very unlikely, and this still does not protect in every case.

Code after:
		ResourceUID::ID uid = p_directory->get_file_uid(i);
		if (uid == ResourceUID::INVALID_ID) {
			continue;
		}

		const StringName engine_type = p_directory->get_file_type(i);
		const StringName script_type = p_directory->get_file_resource_script_class(i);

		const bool is_engine_type = script_type == StringName();
		const StringName &actual_type = is_engine_type ? engine_type : script_type;

		for (const StringName &parent_type : base_types) {
			bool is_valid = ClassDB::is_parent_class(engine_type, parent_type) || (!is_engine_type && EditorNode::get_editor_data().script_class_is_parent(script_type, parent_type));

			if (is_valid) {
				uids.push_back(uid);
				filetypes.insert(uid, actual_type);
				break; // Stop testing base types as soon as we get a match.
			}
		}
	}
}

void QuickOpenResultContainer::set_query_and_update(const String &p_query) {
	query = p_query;
	update_results();
}

Vector<ResourceUID::ID> *QuickOpenResultContainer::_get_history() {
	if (base_types.size() == 1) {
		return selected_history.getptr(base_types[0]);
	}
	return nullptr;
}

QuickOpenResultCandidate QuickOpenResultCandidate::from_uid(const ResourceUID::ID &p_uid, bool &r_success) {
	if (p_uid == ResourceUID::INVALID_ID || !ResourceUID::get_singleton()->has_id(p_uid)) {
		r_success = false;
		return QuickOpenResultCandidate();
	}

	QuickOpenResultCandidate candidate;
	candidate.uid = p_uid;
	candidate.result = nullptr;
	r_success = true;
	return candidate;
}

QuickOpenResultCandidate QuickOpenResultCandidate::from_result(const FuzzySearchResult &p_result, bool &r_success) {
	ResourceUID::ID uid = EditorFileSystem::get_singleton()->get_file_uid(p_result.target);