? token_insert_autofocus.patch
Index: token.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.js,v
retrieving revision 1.3
diff -u -p -r1.3 token.js
--- token.js	20 Mar 2010 19:48:25 -0000	1.3
+++ token.js	20 Feb 2011 23:18:21 -0000
@@ -17,6 +17,10 @@ Drupal.behaviors.tokenInsert = {
       Drupal.settings.tokenFocusedField = this;
     });
 
+    if (typeof Drupal.settings['tokenFocusedField'] != 'undefined') {
+      $(Drupal.settings['tokenFocusedField']).focus();
+    }
+
     $('.token-click-insert .token-key', context).once('token-click-insert', function() {
       var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function(){
         if (typeof Drupal.settings.tokenFocusedField == 'undefined') {
Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.63
diff -u -p -r1.63 token.module
--- token.module	14 Feb 2011 23:22:28 -0000	1.63
+++ token.module	20 Feb 2011 23:18:24 -0000
@@ -121,7 +121,7 @@ function token_theme() {
       'file' => 'token.pages.inc',
     ),
     'token_tree' => array(
-      'variables' => array('token_types' => array(), 'global_types' => TRUE, 'click_insert' => TRUE, 'show_restricted' => FALSE, 'recursion_limit' => 4),
+      'variables' => array('token_types' => array(), 'global_types' => TRUE, 'click_insert' => TRUE, 'insert_target' => '', 'show_restricted' => FALSE, 'recursion_limit' => 4),
       'file' => 'token.pages.inc',
     ),
   );
Index: token.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.pages.inc,v
retrieving revision 1.13
diff -u -p -r1.13 token.pages.inc
--- token.pages.inc	18 Dec 2010 01:53:33 -0000	1.13
+++ token.pages.inc	20 Feb 2011 23:18:24 -0000
@@ -94,6 +94,10 @@ function theme_token_tree($variables) {
     $table_options['attributes']['class'][] = 'token-click-insert';
   }
 
+  if (!empty($variables['insert_target'])) {
+    drupal_add_js(array('tokenFocusedField' => $variables['insert_target']), array('type' => 'setting'));
+  }
+
   return theme('tree_table', $table_options);
 }
 
