@@ -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 ;
0 commit comments