Roundcube Community Forum

SVN Releases => SVN Discussion => Topic started by: marin on November 22, 2006, 03:49:43 AM

Title: Change the way addresses are searched in Compose autocomplete - help needed
Post by: marin on November 22, 2006, 03:49:43 AM
Hello guys,

As you well know currently roundcube searches at all positions the contact information , like when I type "dr" "Andrew" will come up.
There are some folks here who "require" this to be changed to the way their favorite best-ever gmail mail does - meaning what we input is searched for only at the beginning of first name, family name, and email address.
Currently the search function as far as I can see is located in app.js, my js is ground level, so I would be very grateful if someone gives me a hand on this.
Here is what I think does the job now:

Code: [Select]
 /*********   keyboard live-search methods   *********/

 // handler for keyboard events on address-fields
 this.ksearch_keypress = function(e, obj)
  if (typeof(this.env.contacts)!='object' || !this.env.contacts.length)
   return true;

  if (this.ksearch_timer)

  if (!e)
   e = window.event;
  var highlight;
  var key = e.keyCode ? e.keyCode : e.which;

  switch (key)
   case 38: // key up
   case 40: // key down
    if (!this.ksearch_pane)
    var dir = key==38 ? 1 : 0;
    var next;
    highlight = document.getElementById('rcmksearchSelected');
    if (!highlight)
     highlight = this.ksearch_pane.ul.firstChild;
    if (highlight && (next = dir ? highlight.previousSibling : highlight.nextSibling))
     this.set_classname(highlight, 'selected', false);

    if (next)
     next.setAttribute('id', 'rcmksearchSelected');
     this.set_classname(next, 'selected', true);
     this.ksearch_selected = next._rcm_id;

    if (e.preventDefault)
    return false;

   case 9: // tab

   case 13: // enter  
    if (this.ksearch_selected===null || !this.ksearch_input || !this.ksearch_value)

    // get cursor pos
    var inp_value = this.ksearch_input.value.toLowerCase();
    var cpos = this.get_caret_pos(this.ksearch_input);
    var p = inp_value.lastIndexOf(this.ksearch_value, cpos);
    // replace search string with full address
    var pre = this.ksearch_input.value.substring(0, p);
    var end = this.ksearch_input.value.substring(p+this.ksearch_value.length, this.ksearch_input.value.length);
    var insert = this.env.contacts[this.ksearch_selected]+', ';
    this.ksearch_input.value = pre + insert + end;
    //this.ksearch_input.value = this.ksearch_input.value.substring(0, p)+insert;
    // set caret to insert pos
    cpos = p+insert.length;
    if (this.ksearch_input.setSelectionRange)
     this.ksearch_input.setSelectionRange(cpos, cpos);
    // hide ksearch pane
    if (e.preventDefault)
    return false;

   case 27: // escape


Please share your opinions also on whether such behavior should become the default one ?
Title: Re: Change the way addresses are searched in Compose autocomplete - help needed
Post by: Reload on November 22, 2006, 05:28:02 AM
You can share this with the dev. team from RC ;)
( )