I've been wanting to use the Jquery UI autocomplete plugin to autocomplete substrings in a textarea.  To control the carot position while scrolling through autocomplete options, I found I had to modify the autocomplete code to add an option to prevent autocomplete from directly calling self.element.val(...), which resets the caret position.  A patch containing my mods (relative to 1.8.20) is below.  Basically, I added another event hook to control how autocomplete resets the value of the text box.  I'm sure the patch is far from something submittable, but I wanted to get people's thoughts to see if it was a good approach or if there's an easier way.
 
  @@ -974,7 +974,9 @@
 
 
   
   self.menu.select( event );
 
 
   
   break;
 
 
   
   case keyCode.ESCAPE:
 
 
  -
   self.element.val( self.term );
 
 
  +
           if ( false !== self._trigger( "resetvalue", event, { item: self.term } ) ) {
 
 
  +
       self.element.val( self.term );
 
 
  +
           }
 
 
   
   self.close( event );
 
 
   
   break;
 
 
   
   default:
 
 
  @@ -1085,8 +1087,10 @@
 
 
   
   // don't set the value of the text field if it's already correct
 
 
   
   // this prevents moving the cursor unnecessarily
 
 
   
   if ( self.menu.element.is(":visible") &&
 
 
  -
   ( self.element.val() !== self.term ) ) {
 
 
  +
        ( self.element.val() !== self.term ) ) {
 
 
  +
       if ( false !== self._trigger( "resetvalue", event, { item: self.term } ) ) {
 
 
   
   self.element.val( self.term );
 
 
  +
       }
 
 
   
   }
 
 
   
   }
 
 
   
   })
 
 
  @@ -1301,7 +1305,9 @@
 
 
   
   }
 
 
   
   if ( this.menu.first() && /^previous/.test(direction) ||
 
 
   
   this.menu.last() && /^next/.test(direction) ) {
 
 
  -
   this.element.val( this.term );
 
 
  +
          if ( false !== this._trigger( "resetvalue", event, this.term ) ) {
 
 
  +
      this.element.val( this.term );
 
 
  +
          }
 
 
   
   this.menu.deactivate();
 
 
   
   return;
 
 
   
   }