Skip to content

Commit defad85

Browse files
devvaannshabose
authored andcommitted
feat: better resize handling support for maximize and restore option
1 parent fc5702e commit defad85

2 files changed

Lines changed: 87 additions & 6 deletions

File tree

src/view/PanelView.js

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ define(function (require, exports, module) {
7373
/** @type {boolean} Whether the bottom panel is currently maximized */
7474
let _isMaximized = false;
7575

76+
/**
77+
* Pixel threshold for detecting near-maximize state during resize.
78+
* If the editor holder height is within this many pixels of zero, the
79+
* panel is treated as maximized. Keeps the maximize icon responsive
80+
* during drag without being overly sensitive.
81+
* @const
82+
* @type {number}
83+
*/
84+
const MAXIMIZE_THRESHOLD = 2;
85+
86+
/**
87+
* Minimum panel height (matches Resizer minSize) used as a floor
88+
* when computing a sensible restore height.
89+
* @const
90+
* @type {number}
91+
*/
92+
const MIN_PANEL_HEIGHT = 200;
93+
7694
/** @type {number|null} The panel height before maximize, for restore */
7795
let _preMaximizeHeight = null;
7896

@@ -488,14 +506,49 @@ define(function (require, exports, module) {
488506
}
489507
}
490508

509+
/**
510+
* Compute a sensible panel height for restore when the saved height is
511+
* missing or indistinguishable from the maximized height.
512+
* Returns roughly one-third of the total available space, floored at
513+
* MIN_PANEL_HEIGHT so the panel never restores too small.
514+
* @return {number}
515+
* @private
516+
*/
517+
function _getDefaultRestoreHeight() {
518+
let totalHeight = (_$editorHolder ? _$editorHolder.height() : 0) +
519+
(_$container ? _$container.height() : 0);
520+
return Math.max(MIN_PANEL_HEIGHT, Math.round(totalHeight / 3));
521+
}
522+
523+
/**
524+
* Return true if the given height is effectively the same as the
525+
* maximized height (within MAXIMIZE_THRESHOLD).
526+
* @param {number} height
527+
* @return {boolean}
528+
* @private
529+
*/
530+
function _isNearMaxHeight(height) {
531+
let totalHeight = (_$editorHolder ? _$editorHolder.height() : 0) +
532+
(_$container ? _$container.height() : 0);
533+
return (totalHeight - height) <= MAXIMIZE_THRESHOLD;
534+
}
535+
491536
/**
492537
* Restore the bottom panel to its pre-maximize height.
538+
* If the saved height is missing (e.g. maximize was triggered by
539+
* drag-to-max) or was essentially the same as the maximized height,
540+
* a sensible default (≈ 1/3 of available space) is used instead so
541+
* that the restore feels like a visible change.
493542
* @private
494543
*/
495544
function _restorePanel() {
496-
if (_preMaximizeHeight !== null) {
497-
_$container.height(_preMaximizeHeight);
545+
let restoreHeight;
546+
if (_preMaximizeHeight !== null && !_isNearMaxHeight(_preMaximizeHeight)) {
547+
restoreHeight = _preMaximizeHeight;
548+
} else {
549+
restoreHeight = _getDefaultRestoreHeight();
498550
}
551+
_$container.height(restoreHeight);
499552
_isMaximized = false;
500553
_preMaximizeHeight = null;
501554
_updateMaximizeButton();
@@ -538,17 +591,35 @@ define(function (require, exports, module) {
538591
_updateMaximizeButton();
539592
}
540593

594+
/**
595+
* Enter maximize state during a drag-resize that reaches the maximum
596+
* height. No pre-maximize height is stored because the user arrived
597+
* here via continuous dragging; a sensible default will be computed if
598+
* they later click the Restore button.
599+
*/
600+
function enterMaximizeOnResize() {
601+
if (_isMaximized) {
602+
return;
603+
}
604+
_isMaximized = true;
605+
_preMaximizeHeight = null;
606+
_updateMaximizeButton();
607+
}
608+
541609
/**
542610
* Restore the container's CSS height to the pre-maximize value and clear maximize state.
543611
* Must be called BEFORE Resizer.hide() so the Resizer reads the correct height.
544612
* If not maximized, this is a no-op.
613+
* When the saved height is near-max or unknown, a sensible default is used.
545614
*/
546615
function restoreIfMaximized() {
547616
if (!_isMaximized) {
548617
return;
549618
}
550-
if (_preMaximizeHeight !== null) {
619+
if (_preMaximizeHeight !== null && !_isNearMaxHeight(_preMaximizeHeight)) {
551620
_$container.height(_preMaximizeHeight);
621+
} else {
622+
_$container.height(_getDefaultRestoreHeight());
552623
}
553624
_isMaximized = false;
554625
_preMaximizeHeight = null;
@@ -619,8 +690,10 @@ define(function (require, exports, module) {
619690
exports.getOpenBottomPanelIDs = getOpenBottomPanelIDs;
620691
exports.hideAllOpenPanels = hideAllOpenPanels;
621692
exports.exitMaximizeOnResize = exitMaximizeOnResize;
693+
exports.enterMaximizeOnResize = enterMaximizeOnResize;
622694
exports.restoreIfMaximized = restoreIfMaximized;
623695
exports.isMaximized = isMaximized;
696+
exports.MAXIMIZE_THRESHOLD = MAXIMIZE_THRESHOLD;
624697
//events
625698
exports.EVENT_PANEL_HIDDEN = EVENT_PANEL_HIDDEN;
626699
exports.EVENT_PANEL_SHOWN = EVENT_PANEL_SHOWN;

src/view/WorkspaceManager.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,17 @@ define(function (require, exports, module) {
407407
200, false, undefined, true);
408408
listenToResize($bottomPanelContainer);
409409

410-
// Exit maximize state when the user manually drags the resizer
411-
$bottomPanelContainer.on("panelResizeEnd", function () {
412-
PanelView.exitMaximizeOnResize();
410+
// Track maximize state live during drag-resize so the icon updates
411+
// immediately rather than waiting for mouseup. panelResizeUpdate fires
412+
// after listenToResize's handler has already called triggerUpdateLayout(),
413+
// so $editorHolder height is up-to-date at this point.
414+
$bottomPanelContainer.on("panelResizeUpdate panelResizeEnd", function () {
415+
let editorHeight = $editorHolder.height();
416+
if (PanelView.isMaximized() && editorHeight > PanelView.MAXIMIZE_THRESHOLD) {
417+
PanelView.exitMaximizeOnResize();
418+
} else if (!PanelView.isMaximized() && editorHeight <= PanelView.MAXIMIZE_THRESHOLD) {
419+
PanelView.enterMaximizeOnResize();
420+
}
413421
});
414422

415423
$bottomPanelContainer.on("panelCollapsed", function () {

0 commit comments

Comments
 (0)