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

Code before:
	}

	return false;
}

void ScriptTextEditor::set_drop_info_text(const Dictionary &p_info) const {
	String text;
	String c = keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL);
	bool drop_as_uid = bool(EDITOR_GET("text_editor/behavior/files/drop_preload_resources_as_uid"));
	String default_drop_option = drop_as_uid ? TTR("UID path") : TTR("file path");
	String alternate_drop_option = drop_as_uid ? TTR("file path") : TTR("UID path");

	const String type = p_info.get("type", "");

	if (type == "files" || type == "files_and_dirs") {
		Array files = p_info["files"];
		text = TTRN("Drop file path.", "Drop file paths.", files.size()) +
				"\n" + vformat(TTRN("Hold %s: add const preload by %s.", "Hold %s: add const preloads by %s.", files.size()), c, default_drop_option) +
				"\n" + vformat(TTRN("Hold %s+Shift: add const preload by %s.", "Hold %s+Shift: add const preloads by %s.", files.size()), c, alternate_drop_option) +
				"\n" + vformat(TTRN("Hold %s: add @export var pointing to the resource.", "Hold %s: add @export vars pointing to the resources.", files.size()), c);
	} else if (type == "nodes") {
		Array nodes = p_info["nodes"];
		text = TTRN("Drop node path.", "Drop node paths.", nodes.size()) +
				"\n" + vformat(TTRN("Hold %s: add @onready var pointing to the node path.", "Hold %s: add @onready vars pointing to the node paths.", nodes.size()), c) +
				"\n" + vformat(TTRN("Hold %s: add @export var pointing to the node.", "Hold %s: add @export vars pointing to the nodes.", nodes.size()), c);
	} else if (type == "resource") {
		text = TTR("Drop file path.") +
				"\n" + vformat(TTR("Hold %s: add const preload by %s."), c, default_drop_option) +
				"\n" + vformat(TTR("Hold %s+Shift: add const preload by %s."), c, alternate_drop_option) +
				"\n" + TTR("Hold Alt: add @export var pointing to the resource.");
	} else if (type == "obj_property") {
		text = TTR("Drop property path.");
	}

	if (!text.is_empty()) {
		drag_info_label->show();
		drag_info_label->set_text(text);
		drag_info_label->set_anchors_and_offsets_preset(Control::PRESET_BOTTOM_RIGHT, Control::PRESET_MODE_MINSIZE, 20 * EDSCALE);
	}
}

static Node *_find_script_node(Node *p_current_node, const Ref<Script> &script) {
	if (p_current_node->get_script() == script) {
		return p_current_node;
	}

	for (int i = 0; i < p_current_node->get_child_count(); i++) {
		Node *n = _find_script_node(p_current_node->get_child(i), script);
		if (n) {
			return n;
		}

Review comment (suggestion):
The resource branch is the same as the files branch, it just doesn't have a "files" element. We can probably merge them, using `Array files = p_info.get("files", Array());`.

Code after:
					const StringName class_name = custom_class_name.is_empty() ? node->get_class_name() : custom_class_name;
					text_to_drop += vformat("@onready var %s: %s = %c%s", variable_name, class_name, is_unique ? '%' : '$', path);
				} else {
					text_to_drop += vformat("@onready var %s = %c%s", variable_name, is_unique ? '%' : '$', path);
				}
				if (i < nodes.size() - 1) {
					text_to_drop += "\n";
				}
			}

			if (is_empty_line || drop_at_column == 0) {
				text_to_drop += "\n";
			}
		} else if (export_drop_modifier_pressed) {
			Vector<ObjectID> obj_ids = _get_objects_for_export_assignment();

			for (int i = 0; i < nodes.size(); i++) {
				NodePath np = nodes[i];
				Node *node = get_node(np);
				if (!node) {
					continue;
				}

				String variable_name = String(node->get_name()).to_snake_case().validate_unicode_identifier();
				StringName class_name = node->get_class_name();
				Ref<Script> node_script = node->get_script();
				if (node_script.is_valid()) {
					StringName global_node_script_name = node_script->get_global_name();
					if (!global_node_script_name.is_empty()) {
						class_name = global_node_script_name;
					}
				}

				text_to_drop += vformat("@export var %s: %s\n", variable_name, class_name);
				for (ObjectID obj_id : obj_ids) {
					pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, node, class_name });
				}
			}
		} else {
			for (int i = 0; i < nodes.size(); i++) {
				if (i > 0) {
					text_to_drop += ", ";
				}

				NodePath np = nodes[i];
				Node *node = get_node(np);
				if (!node) {
					continue;
				}

				bool is_unique = node->is_unique_name_in_owner() && (node->get_owner() == sn || node->get_owner() == sn->get_owner());