title: jQuery Autocomplete can't replace only part of input value
body: <p>I am trying to make autocomplete like on Github.
  We have a textarea where we write in it some text. We also put -> '@' and try to auto complete a username.</p>
  
  <p>When we the autocomplete script runs it removes all of the text.</p>
  
  <p>My script:</p>
  
  <pre><code>function getSign(text){
    var indexOfAt = text.lastIndexOf('@');
    return indexOfAt;
  };
  
  function changeText(event, ui) {
        var selectedElement = event.target.innerText;
        var text = $(this).val();
        text.replace(/@$/ , selectedElement);
        $(this).val(text);
  }
  
  $(document).ready(function() {
  
    $("textarea#autocomplite").autocomplete({
      source: function(request, response) {
        $.ajax({
          url: "/feeds/autocomplite_search",
          data: { 
            term: request.term.substr(getSign(request.term)+1,request.term.length-getSign(request.term)).trim() 
          },
          success: function(data){
            for(i=0; i&lt;data.length; i++){
              data[i] = '@'+data[i];
            }
            return response(data);
          }
        });
      },
      minLength: 2,
      delay: 400,
      disabled: true,
      search: function() {
        if ( /\s$/.test($(this).val()) ) {
          $(this).autocomplete('disable');
        };
      },
      select: changeText
    });
  
  
    $("textarea#autocomplite").keyup(function() {
      if ( /@$/.test($(this).val()) ) {
        $(this).autocomplete('enable');
      };
    });
  
  });
  </code></pre>