@@ -208,10 +208,9 @@ $.widget( "ui.autocomplete", {
208
208
} ,
209
209
210
210
_getValue : function ( value ) {
211
- //find the caret
212
- this . caretPos = this . element [ 0 ] . selectionStart ;
211
+ this . caretPos = $ . ui . autocomplete . caret ( this . element ) . end ;
213
212
/*
214
- * cut the string in half at the carot , split at the separators,
213
+ * cut the string in half at the caret , split at the separators,
215
214
* and then concat the outter array values so that editing the
216
215
* middle of a string still correctly triggers the autocomplete
217
216
*/
@@ -348,6 +347,34 @@ $.extend( $.ui.autocomplete, {
348
347
return $ . grep ( array , function ( value ) {
349
348
return matcher . test ( value . label || value . value || value ) ;
350
349
} ) ;
350
+ } ,
351
+ caret : function ( element , begin , end ) { //Helper Function for Caret positioning taken from http://dev.jqueryui.com/browser/branches/dev/mask/ui/ui.mask.js?rev=2371
352
+ var input = element [ 0 ] ;
353
+ if ( typeof begin == 'number' ) {
354
+ end = ( typeof end == 'number' ) ? end : begin ;
355
+ if ( input . setSelectionRange ) {
356
+ input . focus ( ) ;
357
+ input . setSelectionRange ( begin , end ) ;
358
+ } else if ( input . createTextRange ) {
359
+ var range = input . createTextRange ( ) ;
360
+ range . collapse ( true ) ;
361
+ range . moveEnd ( 'character' , end ) ;
362
+ range . moveStart ( 'character' , begin ) ;
363
+ range . select ( ) ;
364
+ }
365
+ return element ;
366
+ } else {
367
+ if ( input . setSelectionRange ) {
368
+ begin = input . selectionStart ;
369
+ end = input . selectionEnd ;
370
+ }
371
+ else if ( document . selection && document . selection . createRange ) {
372
+ var range = document . selection . createRange ( ) ;
373
+ begin = 0 - range . duplicate ( ) . moveStart ( 'character' , - 100000 ) ;
374
+ end = begin + range . text . length ;
375
+ }
376
+ return { begin : begin , end : end } ;
377
+ }
351
378
}
352
379
} ) ;
353
380
0 commit comments