浏览代码

Merge pull request #97 from ckeditor/t/96

t/96: Incorrect order management in ControllerCollection bound to another collection
Aleksander Nowodzinski 9 年之前
父节点
当前提交
14f8c4110b

+ 1 - 1
packages/ckeditor5-ui/src/controllercollection.js

@@ -189,7 +189,7 @@ export default class ControllerCollection extends Collection {
 					controllerMap.set( data, controller );
 
 					if ( controller ) {
-						that.add( controller, index ? recalculateIndex( index ) : undefined );
+						that.add( controller, typeof index == 'number' ? recalculateIndex( index ) : undefined );
 					}
 				},
 

+ 10 - 0
packages/ckeditor5-ui/tests/controllercollection.js

@@ -160,6 +160,16 @@ describe( 'ControllerCollection', () => {
 					expect( controllers ).to.have.length( 7 );
 				} );
 
+				it( 'supports adding to the beginning of the collection', () => {
+					const controllers = new ControllerCollection( 'synced' );
+
+					controllers.bind( models ).as( ItemController, ItemView );
+
+					models.add( new Model( { uid: 'x' } ), 0 );
+
+					expect( controllers.map( c => c.model.uid ) ).to.deep.equal( [ 'x', '0', '1', '2', '3', '4' ] );
+				} );
+
 				it( 'supports removing models from the collection', () => {
 					const controllers = new ControllerCollection( 'synced' );