// Fix: Link field dropdown should open on focus even when a value is already selected.
// Frappe core only triggers "input" (which opens the dropdown) when the field is empty.
// This patch makes it always trigger on focus.

$(document).ready(function () {
	const OriginalLink = frappe.ui.form.ControlLink;
	const originalMakeInput = OriginalLink.prototype.make_input;

	OriginalLink.prototype.make_input = function () {
		originalMakeInput.call(this);

		// Replace the focus handler: always trigger "input" so dropdown opens
		this.$input.off("focus").on("focus", () => {
			this.$input.trigger("input");
			this.show_link_and_clear_buttons();
		});
	};
});
