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

Code before:
	base_types = p_base_types;

	const int display_mode_behavior = EDITOR_GET("filesystem/quick_open_dialog/default_display_mode");
	const bool adaptive_display_mode = (display_mode_behavior == 0);

	if (adaptive_display_mode) {
		_set_display_mode(get_adaptive_display_mode(p_base_types));
	} else if (never_opened) {
		int last = EditorSettings::get_singleton()->get_project_metadata("quick_open_dialog", "last_mode", (int)QuickOpenDisplayMode::LIST);
		_set_display_mode((QuickOpenDisplayMode)last);
	}

	const bool do_instant_preview = EDITOR_GET("filesystem/quick_open_dialog/instant_preview");
	const bool fuzzy_matching = EDITOR_GET("filesystem/quick_open_dialog/enable_fuzzy_matching");
	const bool include_addons = EDITOR_GET("filesystem/quick_open_dialog/include_addons");
	instant_preview_toggle->set_pressed_no_signal(do_instant_preview);
	fuzzy_search_toggle->set_pressed_no_signal(fuzzy_matching);
	include_addons_toggle->set_pressed_no_signal(include_addons);
	never_opened = false;

	const bool enable_highlights = EDITOR_GET("filesystem/quick_open_dialog/show_search_highlight");
	for (QuickOpenResultItem *E : result_items) {
		E->enable_highlights = enable_highlights;
	}

	if (history_file->load(_get_cache_file_path()) == OK) {
		// Load history when opening for the first time.
		file_type_icons.insert(SNAME("__default_icon"), get_editor_theme_icon(SNAME("Object")));

		bool history_modified = false;
		Vector<String> history_keys = history_file->get_section_keys("selected_history");
		for (const String &type : history_keys) {
			const StringName type_name = type;
			const PackedStringArray history_uids = history_file->get_value("selected_history", type);

			PackedStringArray cleaned_text_uids;
			cleaned_text_uids.resize(history_uids.size());

			Vector<ResourceUID::ID> cleaned_ids;
			cleaned_ids.resize(history_uids.size());

			{
				String *text_write = cleaned_text_uids.ptrw();
				ResourceUID::ID *id_write = cleaned_ids.ptrw();
				int i = 0;
				for (String uid : history_uids) {
#ifndef DISABLE_DEPRECATED
					if (!uid.begins_with("uid://")) {
						// uid might be a path here, if config was written by older editor version
						ResourceUID::ID id = EditorFileSystem::get_singleton()->get_file_uid(uid);
						if (id == ResourceUID::INVALID_ID) {

Review comment (suggestion):
The file should be loaded only once, just the cleanup should be repeated.

This code does the cleanup while loading from file, so there should be another branch if dialog is opened for the second time and later.

Code after:
	base_types = p_base_types;

	const int display_mode_behavior = EDITOR_GET("filesystem/quick_open_dialog/default_display_mode");
	const bool adaptive_display_mode = (display_mode_behavior == 0);
	const bool first_open = never_opened;

	if (adaptive_display_mode) {
		_set_display_mode(get_adaptive_display_mode(p_base_types));
	} else if (never_opened) {
		int last = EditorSettings::get_singleton()->get_project_metadata("quick_open_dialog", "last_mode", (int)QuickOpenDisplayMode::LIST);
		_set_display_mode((QuickOpenDisplayMode)last);
	}

	const bool do_instant_preview = EDITOR_GET("filesystem/quick_open_dialog/instant_preview");
	const bool fuzzy_matching = EDITOR_GET("filesystem/quick_open_dialog/enable_fuzzy_matching");
	const bool include_addons = EDITOR_GET("filesystem/quick_open_dialog/include_addons");
	instant_preview_toggle->set_pressed_no_signal(do_instant_preview);
	fuzzy_search_toggle->set_pressed_no_signal(fuzzy_matching);
	include_addons_toggle->set_pressed_no_signal(include_addons);
	never_opened = false;

	const bool enable_highlights = EDITOR_GET("filesystem/quick_open_dialog/show_search_highlight");
	for (QuickOpenResultItem *E : result_items) {
		E->enable_highlights = enable_highlights;
	}

	bool history_modified = false;

	if (first_open && history_file->load(_get_cache_file_path()) == OK) {
		// Load history when opening for the first time.
		file_type_icons.insert(SNAME("__default_icon"), get_editor_theme_icon(SNAME("Object")));

		Vector<String> history_keys = history_file->get_section_keys("selected_history");
		for (const String &type : history_keys) {
			const StringName type_name = type;
			const PackedStringArray history_uids = history_file->get_value("selected_history", type);

			PackedStringArray cleaned_text_uids;
			cleaned_text_uids.resize(history_uids.size());

			Vector<ResourceUID::ID> cleaned_ids;
			cleaned_ids.resize(history_uids.size());

			{
				String *text_write = cleaned_text_uids.ptrw();
				ResourceUID::ID *id_write = cleaned_ids.ptrw();
				int i = 0;
				for (String uid : history_uids) {
#ifndef DISABLE_DEPRECATED
					if (!uid.begins_with("uid://")) {
						// uid might be a path here, if config was written by older editor version