Explorar o código

golden-layout: fix focus of tab when closing one

lviguier hai 1 ano
pai
achega
ba32b1d205
Modificáronse 1 ficheiros con 6 adicións e 8 borrados
  1. 6 8
      bin/libs/goldenlayout.js

+ 6 - 8
bin/libs/goldenlayout.js

@@ -4399,22 +4399,20 @@ lm.utils.copy( lm.items.Stack.prototype, {
 
 
 	removeChild: function( contentItem, keepChild ) {
 	removeChild: function( contentItem, keepChild ) {
 		var index = lm.utils.indexOf( contentItem, this.contentItems );
 		var index = lm.utils.indexOf( contentItem, this.contentItems );
+		var curIndex = lm.utils.indexOf( this._activeContentItem, this.contentItems );
 		lm.items.AbstractContentItem.prototype.removeChild.call( this, contentItem, keepChild );
 		lm.items.AbstractContentItem.prototype.removeChild.call( this, contentItem, keepChild );
 		this.header.removeTab( contentItem );
 		this.header.removeTab( contentItem );
 
 
 		if( this.contentItems.length > 0 ) {
 		if( this.contentItems.length > 0 ) {
-			this.setActiveContentItem( this.contentItems[ Math.max( index - 1, 0 ) ] );
+			var indexToFocus = index > curIndex ? curIndex : curIndex - 1;
+			if (curIndex == index)
+				indexToFocus = Math.max( index - 1, 0 );
+
+			this.setActiveContentItem( this.contentItems[ indexToFocus ] );
 		} else {
 		} else {
 			this._activeContentItem = null;
 			this._activeContentItem = null;
 		}
 		}
 
 
-		// var activeContentItem = this.header.parent.getActiveContentItem();
-		// var activeIndex = lm.utils.indexOf( activeContentItem, this.contentItems );
-		// if( activeIndex === index && this.contentItems.length > 0 ) {
-		// 	this.setActiveContentItem( this.contentItems[ Math.max( index - 1, 0 ) ] );
-		// } else {
-		// 	this._activeContentItem = null;
-		// }
 
 
 		this._$validateClosability();
 		this._$validateClosability();
 		this.emitBubblingEvent( 'stateChanged' );
 		this.emitBubblingEvent( 'stateChanged' );