Skip to content

Commit 4cabe6d

Browse files
committed
feat: auto collapse sidebar if needed to fit live preview
1 parent f834771 commit 4cabe6d

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/view/WorkspaceManager.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ define(function (require, exports, module) {
204204
// Floor the toolbar's maxsize at its minimum width. Without the floor, a narrow
205205
// window with a wide sidebar can drive the cap below 10px, and Resizer's drag
206206
// logic would then squeeze the toolbar to zero and hide it.
207-
var rawMax = Math.min(window.innerWidth * 0.75, window.innerWidth - sidebarWidth - 100);
207+
var rawMax = window.innerWidth - sidebarWidth - 100;
208208
$mainToolbar.data("maxsize", Math.max(minToolbarWidth, rawMax));
209209
}
210210

@@ -570,7 +570,7 @@ define(function (require, exports, module) {
570570
let minToolbarWidth = (panelBeingShown.minWidth || 0) + pluginIconsBarWidth;
571571
let maxToolbarWidth = Math.max(
572572
minToolbarWidth,
573-
Math.min(window.innerWidth * 0.75, window.innerWidth - sidebarWidth - 100)
573+
window.innerWidth - sidebarWidth - 100
574574
);
575575
let currentWidth = $mainToolbar.width();
576576
if (currentWidth > maxToolbarWidth || currentWidth < minToolbarWidth) {
@@ -675,7 +675,8 @@ define(function (require, exports, module) {
675675
/**
676676
* Programmatically sets the plugin panel content width to the given value in pixels.
677677
* The total toolbar width is adjusted to account for the plugin icons bar.
678-
* Width is clamped to respect panel minWidth and max size (75% of window).
678+
* If the requested width doesn't fit, the sidebar is progressively shrunk
679+
* (and collapsed if necessary) before clamping.
679680
* No-op if no panel is currently visible.
680681
* @param {number} width Desired content width in pixels
681682
*/
@@ -686,11 +687,31 @@ define(function (require, exports, module) {
686687
var pluginIconsBarWidth = $pluginIconsBar.outerWidth();
687688
var newToolbarWidth = width + pluginIconsBarWidth;
688689

689-
// Respect min/max constraints
690690
var minSize = currentlyShownPanel.minWidth || 0;
691691
var minToolbarWidth = minSize + pluginIconsBarWidth;
692692
var sidebarWidth = _getSidebarWidth();
693-
var maxToolbarWidth = Math.min(window.innerWidth * 0.75, window.innerWidth - sidebarWidth - 100);
693+
var maxToolbarWidth = window.innerWidth - sidebarWidth - MIN_EDITOR_WIDTH;
694+
695+
if (newToolbarWidth > maxToolbarWidth && sidebarWidth > 0) {
696+
var $sb = $("#sidebar");
697+
var deficit = newToolbarWidth - maxToolbarWidth;
698+
var newSidebarWidth = sidebarWidth - deficit;
699+
700+
if (newSidebarWidth >= MIN_SIDEBAR_WIDTH) {
701+
$sb.width(newSidebarWidth);
702+
var resync = $sb.data("resyncSizer");
703+
if (typeof resync === "function") {
704+
resync();
705+
}
706+
$sb.trigger("panelResizeUpdate", [newSidebarWidth]);
707+
$sb.trigger("panelResizeEnd", [newSidebarWidth]);
708+
} else {
709+
Resizer.hide($sb[0]);
710+
}
711+
sidebarWidth = _getSidebarWidth();
712+
maxToolbarWidth = window.innerWidth - sidebarWidth - MIN_EDITOR_WIDTH;
713+
}
714+
694715
newToolbarWidth = Math.max(newToolbarWidth, minToolbarWidth);
695716
newToolbarWidth = Math.min(newToolbarWidth, maxToolbarWidth);
696717

0 commit comments

Comments
 (0)