@@ -292,9 +292,6 @@ Selectize.prototype.onKeyDown = function(e) {
292
292
return ;
293
293
}
294
294
}
295
- if ( ! this . isFull ( ) ) {
296
- this . focus ( true ) ;
297
- }
298
295
} ;
299
296
300
297
/**
@@ -373,7 +370,7 @@ Selectize.prototype.onBlur = function(e) {
373
370
this . close ( ) ;
374
371
this . setTextboxValue ( '' ) ;
375
372
this . setActiveOption ( null ) ;
376
- this . setCaret ( this . items . length , false ) ;
373
+ this . setCaret ( this . items . length ) ;
377
374
if ( ! this . $activeItems . length ) {
378
375
this . $control . removeClass ( 'focus' ) ;
379
376
this . isFocused = false ;
@@ -576,7 +573,6 @@ Selectize.prototype.setActiveOption = function($option, scroll, animate) {
576
573
Selectize . prototype . hideInput = function ( ) {
577
574
this . setTextboxValue ( '' ) ;
578
575
this . $control_input . css ( { opacity : 0 , position : 'absolute' , left : - 10000 } ) ;
579
- this . isInputFocused = false ;
580
576
this . isInputHidden = true ;
581
577
} ;
582
578
@@ -597,12 +593,12 @@ Selectize.prototype.showInput = function() {
597
593
*/
598
594
Selectize . prototype . focus = function ( trigger ) {
599
595
var self = this ;
600
- var fire = trigger && ! this . isInputFocused ;
601
- self . ignoreFocus = ! trigger ;
596
+ self . ignoreFocus = true ;
602
597
self . $control_input [ 0 ] . focus ( ) ;
603
- if ( fire ) self . onFocus ( ) ;
598
+ self . isInputFocused = true ;
604
599
window . setTimeout ( function ( ) {
605
600
self . ignoreFocus = false ;
601
+ if ( trigger ) self . onFocus ( ) ;
606
602
} , 0 ) ;
607
603
} ;
608
604
@@ -1087,14 +1083,16 @@ Selectize.prototype.removeItem = function(value) {
1087
1083
this . removeOption ( value ) ;
1088
1084
}
1089
1085
this . setCaret ( i ) ;
1090
- this . positionDropdown ( ) ;
1091
1086
this . refreshOptions ( false ) ;
1092
1087
this . refreshClasses ( ) ;
1093
1088
1094
1089
if ( ! this . hasOptions ) { this . close ( ) ; }
1095
1090
else if ( this . isInputFocused ) { this . open ( ) ; }
1096
1091
1097
1092
this . updatePlaceholder ( ) ;
1093
+ if ( ! this . items . length ) this . showInput ( ) ;
1094
+
1095
+ this . positionDropdown ( ) ;
1098
1096
this . updateOriginalInput ( ) ;
1099
1097
this . trigger ( 'onItemRemove' , value ) ;
1100
1098
}
@@ -1131,7 +1129,7 @@ Selectize.prototype.createItem = function() {
1131
1129
1132
1130
self . setTextboxValue ( '' ) ;
1133
1131
self . addOption ( value , data ) ;
1134
- self . setCaret ( caret , false ) ;
1132
+ self . setCaret ( caret ) ;
1135
1133
self . addItem ( value ) ;
1136
1134
self . refreshOptions ( true ) ;
1137
1135
self . focus ( false ) ;
@@ -1316,6 +1314,10 @@ Selectize.prototype.deleteSelection = function(e) {
1316
1314
for ( i = 0 , n = this . $activeItems . length ; i < n ; i ++ ) {
1317
1315
values . push ( $ ( this . $activeItems [ i ] ) . attr ( 'data-value' ) ) ;
1318
1316
}
1317
+ if ( e ) {
1318
+ e . preventDefault ( ) ;
1319
+ e . stopPropagation ( ) ;
1320
+ }
1319
1321
} else if ( ( this . isInputFocused || this . settings . mode === 'single' ) && this . items . length ) {
1320
1322
if ( direction < 0 && selection . start === 0 && selection . length === 0 ) {
1321
1323
values . push ( this . items [ this . caretPos - 1 ] ) ;
@@ -1325,7 +1327,7 @@ Selectize.prototype.deleteSelection = function(e) {
1325
1327
}
1326
1328
1327
1329
// allow the callback to abort
1328
- if ( typeof this . settings . onDelete === 'function' && this . settings . onDelete ( values ) === false ) {
1330
+ if ( ! values . length || ( typeof this . settings . onDelete === 'function' && this . settings . onDelete ( values ) === false ) ) {
1329
1331
return ;
1330
1332
}
1331
1333
@@ -1335,10 +1337,7 @@ Selectize.prototype.deleteSelection = function(e) {
1335
1337
}
1336
1338
if ( typeof caret !== 'undefined' ) {
1337
1339
this . setCaret ( caret ) ;
1338
- }
1339
- if ( e ) {
1340
- e . preventDefault ( ) ;
1341
- e . stopPropagation ( ) ;
1340
+ this . showInput ( ) ;
1342
1341
}
1343
1342
} ;
1344
1343
@@ -1353,24 +1352,30 @@ Selectize.prototype.deleteSelection = function(e) {
1353
1352
* @param {object } e (optional)
1354
1353
*/
1355
1354
Selectize . prototype . advanceSelection = function ( direction , e ) {
1355
+ var tail , selection , idx , valueLength , cursorAtEdge , $tail , $items ;
1356
+
1356
1357
if ( direction === 0 ) return ;
1357
- var tail = direction > 0 ? 'last' : 'first' ;
1358
- var selection = getSelection ( this . $control_input [ 0 ] ) ;
1359
1358
1360
- if ( this . isInputFocused ) {
1361
- var valueLength = this . $control_input . val ( ) . length ;
1362
- var cursorAtEdge = direction < 0
1359
+ tail = direction > 0 ? 'last' : 'first' ;
1360
+ selection = getSelection ( this . $control_input [ 0 ] ) ;
1361
+
1362
+ if ( this . isInputFocused && ! this . isInputHidden ) {
1363
+ valueLength = this . $control_input . val ( ) . length ;
1364
+ cursorAtEdge = direction < 0
1363
1365
? selection . start === 0 && selection . length === 0
1364
1366
: selection . start === valueLength ;
1365
1367
1366
1368
if ( cursorAtEdge && ! valueLength ) {
1367
1369
this . advanceCaret ( direction , e ) ;
1368
1370
}
1369
1371
} else {
1370
- var $tail = this . $control . children ( '.active:' + tail ) ;
1372
+ $tail = this . $control . children ( '.active:' + tail ) ;
1371
1373
if ( $tail . length ) {
1372
- var idx = Array . prototype . indexOf . apply ( this . $control [ 0 ] . childNodes , [ $tail [ 0 ] ] ) ;
1374
+ $items = this . $control . children ( ':not(input)' ) ;
1375
+ idx = Array . prototype . indexOf . apply ( $items , [ $tail [ 0 ] ] ) ;
1376
+ this . setActiveItem ( null ) ;
1373
1377
this . setCaret ( direction > 0 ? idx + 1 : idx ) ;
1378
+ this . showInput ( ) ;
1374
1379
}
1375
1380
}
1376
1381
} ;
@@ -1387,7 +1392,7 @@ Selectize.prototype.advanceCaret = function(direction, e) {
1387
1392
if ( this . isShiftDown ) {
1388
1393
var $adj = this . $control_input [ fn ] ( ) ;
1389
1394
if ( $adj . length ) {
1390
- this . blur ( ) ;
1395
+ this . hideInput ( ) ;
1391
1396
this . setActiveItem ( $adj ) ;
1392
1397
e && e . preventDefault ( ) ;
1393
1398
}
@@ -1400,9 +1405,8 @@ Selectize.prototype.advanceCaret = function(direction, e) {
1400
1405
* Moves the caret to the specified index.
1401
1406
*
1402
1407
* @param {int } i
1403
- * @param {boolean } focus
1404
1408
*/
1405
- Selectize . prototype . setCaret = function ( i , focus ) {
1409
+ Selectize . prototype . setCaret = function ( i ) {
1406
1410
if ( this . settings . mode === 'single' ) {
1407
1411
i = this . items . length ;
1408
1412
} else {
@@ -1424,9 +1428,6 @@ Selectize.prototype.setCaret = function(i, focus) {
1424
1428
}
1425
1429
1426
1430
this . caretPos = i ;
1427
- if ( focus && this . isSetup ) {
1428
- this . focus ( true ) ;
1429
- }
1430
1431
} ;
1431
1432
1432
1433
/**
0 commit comments