@@ -172,20 +172,24 @@ define(function (require, exports, module) {
172172 if ( ! _$tabsOverflow ) {
173173 return ;
174174 }
175+ // Detach the add button before emptying to preserve its event handlers
176+ if ( _$addBtn ) {
177+ _$addBtn . detach ( ) ;
178+ }
175179 _$tabsOverflow . empty ( ) ;
176180
177181 _openIds . forEach ( function ( panelId ) {
178- // Default panel uses the external Tools button, not a tab
179- if ( panelId === _defaultPanelId ) {
180- return ;
181- }
182182 let panel = _panelMap [ panelId ] ;
183183 if ( ! panel ) {
184184 return ;
185185 }
186186 _$tabsOverflow . append ( _buildTab ( panel , panelId === _activeId ) ) ;
187187 } ) ;
188188
189+ // Re-append the Tools button at the end
190+ if ( _$addBtn ) {
191+ _$tabsOverflow . append ( _$addBtn ) ;
192+ }
189193 _updateAddButtonVisibility ( ) ;
190194 _checkTabOverflow ( ) ;
191195 }
@@ -218,17 +222,17 @@ define(function (require, exports, module) {
218222 if ( ! _$tabsOverflow ) {
219223 return ;
220224 }
221- // Default panel uses the external Tools button, not a tab
222- if ( panelId === _defaultPanelId ) {
223- _updateAddButtonVisibility ( ) ;
224- return ;
225- }
226225 let panel = _panelMap [ panelId ] ;
227226 if ( ! panel ) {
228227 return ;
229228 }
230229 let $tab = _buildTab ( panel , panelId === _activeId ) ;
231- _$tabsOverflow . append ( $tab ) ;
230+ // Insert before the Tools button so it stays at the end
231+ if ( _$addBtn && _$addBtn . parent ( ) . length ) {
232+ _$addBtn . before ( $tab ) ;
233+ } else {
234+ _$tabsOverflow . append ( $tab ) ;
235+ }
232236 _updateAddButtonVisibility ( ) ;
233237 _checkTabOverflow ( ) ;
234238 }
@@ -243,10 +247,6 @@ define(function (require, exports, module) {
243247 if ( ! _$tabsOverflow ) {
244248 return ;
245249 }
246- if ( panelId === _defaultPanelId ) {
247- _updateAddButtonVisibility ( ) ;
248- return ;
249- }
250250 _$tabsOverflow . find ( '.bottom-panel-tab[data-panel-id="' + panelId + '"]' ) . remove ( ) ;
251251 _updateAddButtonVisibility ( ) ;
252252 _checkTabOverflow ( ) ;
@@ -495,8 +495,11 @@ define(function (require, exports, module) {
495495 if ( ! _$addBtn ) {
496496 return ;
497497 }
498- // Highlight the Tools button as active when the default panel is shown
499- _$addBtn . toggleClass ( "active" , _defaultPanelId && _activeId === _defaultPanelId ) ;
498+ if ( _defaultPanelId && _activeId === _defaultPanelId ) {
499+ _$addBtn . hide ( ) ;
500+ } else {
501+ _$addBtn . show ( ) ;
502+ }
500503 }
501504
502505 /**
@@ -773,13 +776,12 @@ define(function (require, exports, module) {
773776 _recomputeLayout = recomputeLayoutFn ;
774777 _defaultPanelId = defaultPanelId ;
775778
776- // Create the "Tools" button outside the scrollable tabs area
777- // so it's always visible even when tabs overflow.
779+ // Create the "Tools" button inside the scrollable tabs area.
778780 _$addBtn = $ ( '<span class="bottom-panel-add-btn" title="' + Strings . BOTTOM_PANEL_DEFAULT_TITLE + '">'
779781 + '<img class="app-drawer-tab-icon" src="styles/images/app-drawer.svg"'
780782 + ' style="width:12px;height:12px;vertical-align:middle;margin-right:4px">'
781783 + Strings . BOTTOM_PANEL_DEFAULT_TITLE + '</span>' ) ;
782- _$tabBar . find ( ".bottom-panel-tab-bar-actions" ) . before ( _$addBtn ) ;
784+ _$tabsOverflow . append ( _$addBtn ) ;
783785
784786 // Tab bar click handlers
785787 _$tabBar . on ( "click" , ".bottom-panel-tab-close-btn" , function ( e ) {
0 commit comments