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

Code before:

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

	StringName type = base_types[0];

	Vector<QuickOpenResultCandidate> *history = selected_history.getptr(type);
	if (!history) {
		return nullptr;
	}

	Vector<QuickOpenResultCandidate> valid_history;
	bool history_changed = false;
	EditorFileSystem *efs = EditorFileSystem::get_singleton();

	for (const QuickOpenResultCandidate &candidate : *history) {
		if (FileAccess::exists(candidate.file_path) && efs->get_file_type(candidate.file_path) == type) {
			valid_history.push_back(candidate);
		} else {
			history_changed = true;
		}
	}

	if (valid_history.size() == 0) {
		selected_history.erase(type);
		return nullptr;
	}

	if (history_changed) {
		*history = valid_history;
	}

	return history;
}

void QuickOpenResultContainer::_setup_candidate(QuickOpenResultCandidate &p_candidate, const String &p_filepath) {
	p_candidate.file_path = ResourceUID::ensure_path(p_filepath);
	p_candidate.result = nullptr;
	StringName actual_type;
	{
		StringName *actual_type_ptr = filetypes.getptr(p_filepath);
		if (actual_type_ptr) {
			actual_type = *actual_type_ptr;
		} else {
			ERR_PRINT(vformat("EditorQuickOpenDialog: No type for path %s.", p_candidate.file_path));
		}
	}
	EditorResourcePreview::PreviewItem item = EditorResourcePreview::get_singleton()->get_resource_preview_if_available(p_candidate.file_path);
	if (item.preview.is_valid()) {

Review comment (suggestion):
```suggestion
	if (valid_history.is_empty()) {
```

Code after:
	_sort_uids(result_items.size());
	max_total_results = MIN(uids.size(), result_items.size());
	update_results();
}

void QuickOpenResultContainer::_find_uids_in_folder(EditorFileSystemDirectory *p_directory, bool p_include_addons) {
	for (int i = 0; i < p_directory->get_subdir_count(); i++) {
		if (p_include_addons || p_directory->get_name() != "addons") {
			_find_uids_in_folder(p_directory->get_subdir(i), p_include_addons);
		}
	}

	for (int i = 0; i < p_directory->get_file_count(); i++) {
		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;