Skip to content

Commit 50288db

Browse files
committed
Code cleanup for autocomplete multiple word support
1 parent 1a734e9 commit 50288db

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,13 @@ $.widget( "ui.autocomplete", {
208208
},
209209

210210
_getValue: function( value ){
211+
//find the caret
211212
this.caretPos = this.element[0].selectionStart;
213+
/*
214+
* cut the string in half at the carot, split at the separators,
215+
* and then concat the outter array values so that editing the
216+
* middle of a string still correctly triggers the autocomplete
217+
*/
212218
var begin = value.substr( 0, this.caretPos ).split( this.options.separator ),
213219
end = value.substr( this.caretPos ).split( this.options.separator );
214220
return begin[ begin.length-1 ] + end[0];
@@ -218,8 +224,11 @@ $.widget( "ui.autocomplete", {
218224
var begin = this.term.substr( 0, this.caretPos ).split( this.options.separator ),
219225
end = this.term.substr( this.caretPos ).split( this.options.separator ),
220226
result = '';
227+
228+
//clean the arrays of empty entries
221229
begin.pop();
222230
end.shift();
231+
223232
if(begin.length){
224233
result = begin.join( this.options.separator ) + this.options.separator;
225234
}

0 commit comments

Comments
 (0)