protected CodeUnit getCodeUnit(ActionContext context) {
		if (!(context instanceof ListingActionContext)) {
			return null;
		}

		ListingActionContext lac = (ListingActionContext) context;
		ComponentProvider provider = lac.getComponentProvider();
		if (!(provider instanceof CodeViewerProvider)) {
			return null;
		}

		CodeViewerProvider codeViewProvider = (CodeViewerProvider) provider;
		if (codeViewProvider.isReadOnly()) {
			return null;
		}
		return lac.getCodeUnit();
	}
Pre-fill the input fields and place the caret appropriately (usually at the end)
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/AbstractPatchAction.java