@@ -88,6 +88,20 @@ define(function (require, exports, module) {
8888 */
8989 const MAIN_TOOLBAR_WIDTH = 30 ;
9090
91+ /**
92+ * Returns the sidebar's rendered width, or 0 if hidden. jQuery's outerWidth()
93+ * on a display:none element that still carries an explicit style.width returns
94+ * that stale width rather than 0, which corrupts main-view layout math.
95+ * @private
96+ */
97+ function _getSidebarWidth ( ) {
98+ var sb = document . getElementById ( "sidebar" ) ;
99+ if ( ! sb || sb . offsetWidth === 0 ) {
100+ return 0 ;
101+ }
102+ return sb . offsetWidth ;
103+ }
104+
91105 /**
92106 * The ".content" vertical stack (editor + all header/footer panels)
93107 * @type {jQueryObject }
@@ -184,8 +198,14 @@ define(function (require, exports, module) {
184198 }
185199 } ) ;
186200
187- var sidebarWidth = $ ( "#sidebar" ) . outerWidth ( ) || 0 ;
188- $mainToolbar . data ( "maxsize" , Math . min ( window . innerWidth * 0.75 , window . innerWidth - sidebarWidth - 100 ) ) ;
201+ var sidebarWidth = _getSidebarWidth ( ) ;
202+ var pluginIconsBarWidth = $pluginIconsBar . outerWidth ( ) || MAIN_TOOLBAR_WIDTH ;
203+ var minToolbarWidth = ( ( currentlyShownPanel && currentlyShownPanel . minWidth ) || 0 ) + pluginIconsBarWidth ;
204+ // Floor the toolbar's maxsize at its minimum width. Without the floor, a narrow
205+ // window with a wide sidebar can drive the cap below 10px, and Resizer's drag
206+ // logic would then squeeze the toolbar to zero and hide it.
207+ var rawMax = Math . min ( window . innerWidth * 0.75 , window . innerWidth - sidebarWidth - 100 ) ;
208+ $mainToolbar . data ( "maxsize" , Math . max ( minToolbarWidth , rawMax ) ) ;
189209 }
190210
191211
@@ -224,6 +244,8 @@ define(function (require, exports, module) {
224244 if ( currentlyShownPanel && $mainToolbar . is ( ":visible" ) ) {
225245 _clampPluginPanelWidth ( currentlyShownPanel ) ;
226246 }
247+ // Then coordinate sidebar width in editor mode so the three regions fit.
248+ _ensureEditorLayoutFits ( ) ;
227249
228250 // FIXME (issue #4564) Workaround https://github.com/codemirror/CodeMirror/issues/1787
229251 triggerUpdateLayout ( ) ;
@@ -375,6 +397,19 @@ define(function (require, exports, module) {
375397 $mainPluginPanel = $ ( "#main-plugin-panel" ) ;
376398 $pluginIconsBar = $ ( "#plugin-icons-bar" ) ;
377399
400+ // Sidebar show/resize steals width from the plugin-panel area. Without
401+ // re-clamping, the main-toolbar keeps its previous (now-oversized) width
402+ // and overlaps the sidebar/editor. Mirror the window-resize handling.
403+ $ ( "#sidebar" ) . on ( "panelExpanded.workspace panelCollapsed.workspace panelResizeEnd.workspace" ,
404+ function ( ) {
405+ if ( currentlyShownPanel && $mainToolbar . is ( ":visible" ) ) {
406+ _clampPluginPanelWidth ( currentlyShownPanel ) ;
407+ }
408+ _ensureEditorLayoutFits ( ) ;
409+ triggerUpdateLayout ( ) ;
410+ updateResizeLimits ( ) ;
411+ } ) ;
412+
378413 // --- Create the bottom panel tabbed container ---
379414 $bottomPanelContainer = $ ( '<div id="bottom-panel-container" class="vert-resizable top-resizer"></div>' ) ;
380415 let $bottomPanelTabBar = $ ( '<div id="bottom-panel-tab-bar"></div>' ) ;
@@ -530,7 +565,7 @@ define(function (require, exports, module) {
530565 }
531566
532567 function _clampPluginPanelWidth ( panelBeingShown ) {
533- let sidebarWidth = $ ( "#sidebar" ) . outerWidth ( ) || 0 ;
568+ let sidebarWidth = _getSidebarWidth ( ) ;
534569 let pluginIconsBarWidth = $pluginIconsBar . outerWidth ( ) ;
535570 let minToolbarWidth = ( panelBeingShown . minWidth || 0 ) + pluginIconsBarWidth ;
536571 let maxToolbarWidth = Math . max (
@@ -546,6 +581,45 @@ define(function (require, exports, module) {
546581 }
547582 }
548583
584+ const CCB_WIDTH = 30 ;
585+ const MIN_EDITOR_WIDTH = 100 ;
586+ const MIN_SIDEBAR_WIDTH = 30 ;
587+
588+ /**
589+ * In editor mode the sidebar, editor, and plugin-panel (main-toolbar) must
590+ * share the horizontal space. Resizer's own sidebar clamp runs lazily on
591+ * the next mousemove, and only considers percent-based max sizes — so a
592+ * window shrink, or showing the sidebar at its remembered width, can leave
593+ * the sidebar overlapping the live-preview panel. Here we do an eager
594+ * coordinated shrink: clamp sidebar so sidebar + CCB + current toolbar +
595+ * MIN_EDITOR_WIDTH fits in the window. Design mode handles its own
596+ * geometry with !important, so this is a no-op there.
597+ * @private
598+ */
599+ function _ensureEditorLayoutFits ( ) {
600+ if ( _isInDesignMode ) {
601+ return ;
602+ }
603+ var $sb = $ ( "#sidebar" ) ;
604+ if ( ! $sb . length || $sb [ 0 ] . offsetWidth === 0 ) {
605+ return ;
606+ }
607+ var toolbarW = $mainToolbar . is ( ":visible" ) ? $mainToolbar . width ( ) : 0 ;
608+ var maxSidebar = window . innerWidth - CCB_WIDTH - toolbarW - MIN_EDITOR_WIDTH ;
609+ var currentSb = $sb [ 0 ] . offsetWidth ;
610+ if ( currentSb > maxSidebar ) {
611+ var newSb = Math . max ( MIN_SIDEBAR_WIDTH , maxSidebar ) ;
612+ $sb . width ( newSb ) ;
613+ var resync = $sb . data ( "resyncSizer" ) ;
614+ if ( typeof resync === "function" ) {
615+ resync ( ) ;
616+ }
617+ // Notify listeners (CCB syncs its left offset; content tracks via forceleft).
618+ $sb . trigger ( "panelResizeUpdate" , [ newSb ] ) ;
619+ $sb . trigger ( "panelResizeEnd" , [ newSb ] ) ;
620+ }
621+ }
622+
549623 function _showPluginSidePanel ( panelID ) {
550624 let panelBeingShown = getPanelForID ( panelID ) ;
551625 let pluginIconsBarWidth = $pluginIconsBar . outerWidth ( ) ;
@@ -615,7 +689,7 @@ define(function (require, exports, module) {
615689 // Respect min/max constraints
616690 var minSize = currentlyShownPanel . minWidth || 0 ;
617691 var minToolbarWidth = minSize + pluginIconsBarWidth ;
618- var sidebarWidth = $ ( "#sidebar" ) . outerWidth ( ) || 0 ;
692+ var sidebarWidth = _getSidebarWidth ( ) ;
619693 var maxToolbarWidth = Math . min ( window . innerWidth * 0.75 , window . innerWidth - sidebarWidth - 100 ) ;
620694 newToolbarWidth = Math . max ( newToolbarWidth , minToolbarWidth ) ;
621695 newToolbarWidth = Math . min ( newToolbarWidth , maxToolbarWidth ) ;
0 commit comments