@@ -369,29 +369,30 @@ angular.module('ui.sortable', [])
369
369
// If the received flag hasn't be set on the item, this is a
370
370
// normal sort, if dropindex is set, the item was moved, so move
371
371
// the items in the list.
372
- if ( ! ui . item . sortable . received &&
373
- ( 'dropindex' in ui . item . sortable ) &&
374
- ! ui . item . sortable . isCanceled ( ) ) {
372
+ var wasMoved = ( 'dropindex' in ui . item . sortable ) &&
373
+ ! ui . item . sortable . isCanceled ( ) ;
374
+
375
+ if ( wasMoved && ! ui . item . sortable . received ) {
375
376
376
377
scope . $apply ( function ( ) {
377
378
ngModel . $modelValue . splice (
378
379
ui . item . sortable . dropindex , 0 ,
379
380
ngModel . $modelValue . splice ( ui . item . sortable . index , 1 ) [ 0 ] ) ;
380
381
} ) ;
381
- } else {
382
- // if the item was not moved, then restore the elements
382
+ } else if ( ! wasMoved &&
383
+ ! angular . equals ( element . contents ( ) . toArray ( ) , savedNodes . toArray ( ) ) ) {
384
+ // if the item was not moved
385
+ // and the DOM element order has changed,
386
+ // then restore the elements
383
387
// so that the ngRepeat's comment are correct.
384
- if ( ( ! ( 'dropindex' in ui . item . sortable ) || ui . item . sortable . isCanceled ( ) ) &&
385
- ! angular . equals ( element . contents ( ) , savedNodes ) ) {
386
-
387
- var sortingHelper = getSortingHelper ( element , ui , savedNodes ) ;
388
- if ( sortingHelper && sortingHelper . length ) {
389
- // Restore all the savedNodes except from the sorting helper element.
390
- // That way it will be garbage collected.
391
- savedNodes = savedNodes . not ( sortingHelper ) ;
392
- }
393
- savedNodes . appendTo ( element ) ;
388
+
389
+ var sortingHelper = getSortingHelper ( element , ui , savedNodes ) ;
390
+ if ( sortingHelper && sortingHelper . length ) {
391
+ // Restore all the savedNodes except from the sorting helper element.
392
+ // That way it will be garbage collected.
393
+ savedNodes = savedNodes . not ( sortingHelper ) ;
394
394
}
395
+ savedNodes . appendTo ( element ) ;
395
396
}
396
397
397
398
// It's now safe to clear the savedNodes
0 commit comments