@@ -18,12 +18,11 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
1818import { Widget } from 'vs/base/browser/ui/widget' ;
1919import { isUndefinedOrNull } from 'vs/base/common/types' ;
2020import { IColorTheme } from 'vs/platform/theme/common/themeService' ;
21- import { Emitter , Event } from 'vs/base/common/event' ;
21+ import { Emitter } from 'vs/base/common/event' ;
2222import { ViewContainerLocation , IViewDescriptorService } from 'vs/workbench/common/views' ;
2323import { IPaneComposite } from 'vs/workbench/common/panecomposite' ;
2424import { IComposite } from 'vs/workbench/common/composite' ;
2525import { CompositeDragAndDropData , CompositeDragAndDropObserver , IDraggedCompositeData , ICompositeDragAndDrop , Before2D } from 'vs/workbench/browser/dnd' ;
26- import { generateUuid } from 'vs/base/common/uuid' ;
2726
2827export interface ICompositeBarItem {
2928 id : string ;
@@ -103,7 +102,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
103102
104103 const items = this . getItems ( ) ;
105104 const before = this . targetContainerLocation === ViewContainerLocation . Panel ? before2d ?. horizontallyBefore : before2d ?. verticallyBefore ;
106- return items . filter ( o => o . visible ) . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
105+ return items . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
107106 }
108107
109108 private canDrop ( data : CompositeDragAndDropData , targetCompositeId : string | undefined ) : boolean {
@@ -285,9 +284,9 @@ export class CompositeBar extends Widget implements ICompositeBar {
285284 this . updateCompositeSwitcher ( ) ;
286285 }
287286
288- addComposite ( { id, name, order, requestedIndex } : { id : string ; name : string , order ?: number , requestedIndex ?: number } ) : void {
287+ addComposite ( { id, name, order } : { id : string ; name : string , order ?: number } ) : void {
289288 // Add to the model
290- if ( this . model . add ( id , name , order , requestedIndex ) ) {
289+ if ( this . model . add ( id , name , order ) ) {
291290 this . computeSizes ( [ this . model . findItem ( id ) ] ) ;
292291 this . updateCompositeSwitcher ( ) ;
293292 }
@@ -675,9 +674,17 @@ class CompositeBarModel {
675674 this . _items = result ;
676675 }
677676
677+ this . updateItemsOrder ( ) ;
678678 return hasChanges ;
679679 }
680680
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+
681688 get visibleItems ( ) : ICompositeBarModelItem [ ] {
682689 return this . items . filter ( item => item . visible ) ;
683690 }
@@ -700,7 +707,7 @@ class CompositeBarModel {
700707 } ;
701708 }
702709
703- add ( id : string , name : string , order : number | undefined , requestedIndex : number | undefined ) : boolean {
710+ add ( id : string , name : string , order : number | undefined ) : boolean {
704711 const item = this . findItem ( id ) ;
705712 if ( item ) {
706713 let changed = false ;
@@ -714,20 +721,11 @@ class CompositeBarModel {
714721 changed = true ;
715722 }
716723
724+ this . updateItemsOrder ( ) ;
717725 return changed ;
718726 } else {
719727 const item = this . createCompositeBarItem ( id , name , order , true , true ) ;
720- if ( ! isUndefinedOrNull ( requestedIndex ) ) {
721- let index = 0 ;
722- let rIndex = requestedIndex ;
723- while ( rIndex > 0 && index < this . items . length ) {
724- if ( this . items [ index ++ ] . visible ) {
725- rIndex -- ;
726- }
727- }
728-
729- this . items . splice ( index , 0 , item ) ;
730- } else if ( isUndefinedOrNull ( order ) ) {
728+ if ( isUndefinedOrNull ( order ) ) {
731729 this . items . push ( item ) ;
732730 } else {
733731 let index = 0 ;
@@ -737,6 +735,7 @@ class CompositeBarModel {
737735 this . items . splice ( index , 0 , item ) ;
738736 }
739737
738+ this . updateItemsOrder ( ) ;
740739 return true ;
741740 }
742741 }
@@ -745,6 +744,7 @@ class CompositeBarModel {
745744 for ( let index = 0 ; index < this . items . length ; index ++ ) {
746745 if ( this . items [ index ] . id === id ) {
747746 this . items . splice ( index , 1 ) ;
747+ this . updateItemsOrder ( ) ;
748748 return true ;
749749 }
750750 }
@@ -780,6 +780,8 @@ class CompositeBarModel {
780780 // Make sure a moved composite gets pinned
781781 sourceItem . pinned = true ;
782782
783+ this . updateItemsOrder ( ) ;
784+
783785 return true ;
784786 }
785787
0 commit comments