@@ -102,7 +102,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
102102
103103 const items = this . getItems ( ) ;
104104 const before = this . targetContainerLocation === ViewContainerLocation . Panel ? before2d ?. horizontallyBefore : before2d ?. verticallyBefore ;
105- return items . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
105+ return items . filter ( o => o . visible ) . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
106106 }
107107
108108 private canDrop ( data : CompositeDragAndDropData , targetCompositeId : string | undefined ) : boolean {
@@ -284,9 +284,9 @@ export class CompositeBar extends Widget implements ICompositeBar {
284284 this . updateCompositeSwitcher ( ) ;
285285 }
286286
287- addComposite ( { id, name, order } : { id : string ; name : string , order ?: number } ) : void {
287+ addComposite ( { id, name, order, requestedIndex } : { id : string ; name : string , order ?: number , requestedIndex ?: number } ) : void {
288288 // Add to the model
289- if ( this . model . add ( id , name , order ) ) {
289+ if ( this . model . add ( id , name , order , requestedIndex ) ) {
290290 this . computeSizes ( [ this . model . findItem ( id ) ] ) ;
291291 this . updateCompositeSwitcher ( ) ;
292292 }
@@ -674,17 +674,9 @@ class CompositeBarModel {
674674 this . _items = result ;
675675 }
676676
677- this . updateItemsOrder ( ) ;
678677 return hasChanges ;
679678 }
680679
681-
682- private updateItemsOrder ( ) : void {
683- if ( this . _items ) {
684- this . items . forEach ( ( item , index ) => { if ( item . order !== undefined ) { item . order = index ; } } ) ;
685- }
686- }
687-
688680 get visibleItems ( ) : ICompositeBarModelItem [ ] {
689681 return this . items . filter ( item => item . visible ) ;
690682 }
@@ -707,7 +699,7 @@ class CompositeBarModel {
707699 } ;
708700 }
709701
710- add ( id : string , name : string , order : number | undefined ) : boolean {
702+ add ( id : string , name : string , order : number | undefined , requestedIndex : number | undefined ) : boolean {
711703 const item = this . findItem ( id ) ;
712704 if ( item ) {
713705 let changed = false ;
@@ -721,11 +713,20 @@ class CompositeBarModel {
721713 changed = true ;
722714 }
723715
724- this . updateItemsOrder ( ) ;
725716 return changed ;
726717 } else {
727718 const item = this . createCompositeBarItem ( id , name , order , true , true ) ;
728- if ( isUndefinedOrNull ( order ) ) {
719+ if ( ! isUndefinedOrNull ( requestedIndex ) ) {
720+ let index = 0 ;
721+ let rIndex = requestedIndex ;
722+ while ( rIndex > 0 && index < this . items . length ) {
723+ if ( this . items [ index ++ ] . visible ) {
724+ rIndex -- ;
725+ }
726+ }
727+
728+ this . items . splice ( index , 0 , item ) ;
729+ } else if ( isUndefinedOrNull ( order ) ) {
729730 this . items . push ( item ) ;
730731 } else {
731732 let index = 0 ;
@@ -735,7 +736,6 @@ class CompositeBarModel {
735736 this . items . splice ( index , 0 , item ) ;
736737 }
737738
738- this . updateItemsOrder ( ) ;
739739 return true ;
740740 }
741741 }
@@ -744,7 +744,6 @@ class CompositeBarModel {
744744 for ( let index = 0 ; index < this . items . length ; index ++ ) {
745745 if ( this . items [ index ] . id === id ) {
746746 this . items . splice ( index , 1 ) ;
747- this . updateItemsOrder ( ) ;
748747 return true ;
749748 }
750749 }
@@ -780,8 +779,6 @@ class CompositeBarModel {
780779 // Make sure a moved composite gets pinned
781780 sourceItem . pinned = true ;
782781
783- this . updateItemsOrder ( ) ;
784-
785782 return true ;
786783 }
787784
0 commit comments