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

Code before:
	assign->set_tooltip_text(String(p));

	if (p.is_empty()) {
		assign->set_button_icon(Ref<Texture2D>());
		assign->set_text(TTR("Assign..."));
		assign->set_flat(false);
		return;
	}
	assign->set_flat(true);

	if (!base_node || !base_node->has_node(p)) {
		assign->set_button_icon(Ref<Texture2D>());
		assign->set_text(String(p));
		return;
	}

	const Node *target_node = base_node->get_node(p);
	ERR_FAIL_NULL(target_node);

	if (String(target_node->get_name()).contains_char('@')) {
		assign->set_button_icon(Ref<Texture2D>());
		assign->set_text(String(p));
		return;
	}

	String new_text = target_node->get_name();
	if (p.get_subname_count() > 0) {
		new_text += ":" + p.get_concatenated_subnames();
	}
	assign->set_text(new_text);
	assign->set_button_icon(EditorNode::get_singleton()->get_object_icon(target_node));
}

void EditorPropertyNodePath::setup(const Vector<StringName> &p_valid_types, bool p_use_path_from_scene_root, bool p_editing_node) {
	valid_types = p_valid_types;
	editing_node = p_editing_node;
	use_path_from_scene_root = p_use_path_from_scene_root;
}

void EditorPropertyNodePath::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
			menu->get_popup()->set_item_icon(ACTION_CLEAR, get_editor_theme_icon(SNAME("Clear")));
			menu->get_popup()->set_item_icon(ACTION_COPY, get_editor_theme_icon(SNAME("ActionCopy")));
			menu->get_popup()->set_item_icon(ACTION_EDIT, get_editor_theme_icon(SNAME("Edit")));
			menu->get_popup()->set_item_icon(ACTION_SELECT, get_editor_theme_icon(SNAME("ExternalLink")));
		} break;

		case NOTIFICATION_DRAG_BEGIN: {
			if (!is_read_only() && is_drop_valid(get_viewport()->gui_get_drag_data())) {

Review comment (suggestion):
You could put this variable above and use it in the `String(target_node->get_name())` condition.

Code after:
		case ACTION_SELECT: {
			const Node *edited_node = get_base_node();
			ERR_FAIL_NULL(edited_node);

			const NodePath &np = _get_node_path();
			Node *target_node = edited_node->get_node_or_null(np);
			ERR_FAIL_NULL(target_node);

			SceneTreeDock::get_singleton()->set_selected(target_node);
		} break;
	}
}

void EditorPropertyNodePath::_accept_text() {
	_text_submitted(edit->get_text());
}

void EditorPropertyNodePath::_text_submitted(const String &p_text) {
	NodePath np = p_text;
	_node_selected(np, false);
	edit->hide();
	assign->show();
	menu->show();
}

const NodePath EditorPropertyNodePath::_get_node_path() const {
	const Node *base_node = const_cast<EditorPropertyNodePath *>(this)->get_base_node();

	Variant val = get_edited_property_value();
	Node *n = Object::cast_to<Node>(val);
	if (n) {
		if (!n->is_inside_tree()) {
			return NodePath();
		}
		if (base_node) {
			return base_node->get_path_to(n);
		} else {
			return get_tree()->get_edited_scene_root()->get_path_to(n);
		}
	} else {
		return val;
	}
}

bool EditorPropertyNodePath::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
	return !is_read_only() && is_drop_valid(p_data);
}

void EditorPropertyNodePath::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
	ERR_FAIL_COND(!is_drop_valid(p_data));
	Dictionary data_dict = p_data;