Skip to content

Commit c6ea743

Browse files
committed
fix: right toolbar disappearing and sidebar overflow in editor mode
- Guard Resizer drag-hide behind the collapsible flag so non-collapsible panels (main-toolbar, pane splitters, bottom-panel-container) cannot be squeezed to zero and hidden when maxsize is driven below 10px by a narrow window. - Floor main-toolbar's data("maxsize") at its minimum width in updateResizeLimits, so narrow-window/wide-sidebar cases cannot cap the toolbar below usable size. - Add _getSidebarWidth() using offsetWidth; jQuery outerWidth() returns the stale style.width on a display:none sidebar, which corrupted the layout math. - Re-clamp the plugin panel when the sidebar is shown/hidden/resized. - Add _ensureEditorLayoutFits(): in editor mode, coordinate sidebar, editor, and plugin-panel so all three share the window. Shrinks the sidebar after toolbar clamping if sidebar + CCB + toolbar + min editor exceeds the window width. No-op in design mode, which pins its own geometry with !important.
1 parent 228984b commit c6ea743

2 files changed

Lines changed: 88 additions & 10 deletions

File tree

src/utils/Resizer.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,22 +503,26 @@ define(function (require, exports, module) {
503503
previousSize = newSize;
504504

505505
if ($element.is(":visible")) {
506-
if (newSize < 10) {
506+
if (collapsible && newSize < 10) {
507507
toggle($element);
508508
elementSizeFunction.apply($element, [0]);
509509
} else {
510-
// Trigger resizeStarted just before the first successful resize update
510+
// Non-collapsible panels must never be auto-hidden by a drag that
511+
// squeezes them to near-zero — a narrow window with a wide sidebar
512+
// can push maxsize below 10, and hiding the toolbar that way
513+
// strands the user with no way to get it back.
514+
var effectiveSize = collapsible ? newSize : Math.max(newSize, minSize);
511515
if (!resizeStarted) {
512516
resizeStarted = true;
513-
$element.trigger(EVENT_PANEL_RESIZE_START, newSize);
517+
$element.trigger(EVENT_PANEL_RESIZE_START, effectiveSize);
514518
}
515519

516520
// Resize the main element to the new size. If there is a content element,
517521
// its size is the new size minus the size of the non-resizable elements
518-
resizeElement(newSize, (newSize - baseSize));
519-
adjustSibling(newSize);
522+
resizeElement(effectiveSize, (effectiveSize - baseSize));
523+
adjustSibling(effectiveSize);
520524

521-
$element.trigger(EVENT_PANEL_RESIZE_UPDATE, [newSize]);
525+
$element.trigger(EVENT_PANEL_RESIZE_UPDATE, [effectiveSize]);
522526
}
523527
} else if (newSize > 10) {
524528
elementSizeFunction.apply($element, [newSize]);

src/view/WorkspaceManager.js

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)