Changeset 13615

Show
Ignore:
Timestamp:
05/07/08 05:50:32 (7 months ago)
Author:
wolfram
Message:

+ refs#6461, make highlightMatch find matches only at the beginning of a string and at word boundaries, this is more natural

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/form/ComboBox.js

    r13614 r13615  
    649649                        //              highlights the first occurence found. Override this method 
    650650                        //              to implement your custom highlighing. 
    651                         return this._escapeHtml(label).replace( 
    652                                 // Add greedy when this.highlightMatch=="all" 
    653                                 new RegExp("("+ this._escapeHtml(this._lastInput) +")", "i"+(this.highlightMatch=="all"?"g":"")), 
    654                                 '<span class="dijitComboBoxHighlightMatch">$1</span>'); 
    655                         // returns String, (almost) valid HTML (entities encoded) 
     651                        var find = this._escapeHtml(this._lastInput); 
     652                        // Add greedy when this.highlightMatch=="all" 
     653                        var modifiers = "i"+(this.highlightMatch=="all"?"g":""); 
     654                        var escapedLabel = this._escapeHtml(label); 
     655                        ret = escapedLabel.replace(new RegExp("^("+ find +")", modifiers), 
     656                                        '<span class="dijitComboBoxHighlightMatch">$1</span>'); 
     657                        if (escapedLabel==ret){ // Nothing replaced, try to replace at word boundaries. 
     658                                ret = escapedLabel.replace(new RegExp(" ("+ find +")", modifiers), 
     659                                        ' <span class="dijitComboBoxHighlightMatch">$1</span>'); 
     660                        } 
     661                        return ret;// returns String, (almost) valid HTML (entities encoded) 
    656662                }, 
    657663