Skip to content

Commit 44611ec

Browse files
devvaannshabose
authored andcommitted
refactor: better api support for bottom panel architecture
1 parent 0f9ac07 commit 44611ec

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

src/view/PanelView.js

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,10 @@ define(function (require, exports, module) {
669669
};
670670

671671
/**
672-
* Requests the panel to hide, invoking the registered onCloseRequested handler first (if any).
673-
* If the handler returns false, the panel stays open. If it returns true or no handler is
674-
* registered, `hide()` is called.
675-
* @return {Promise<boolean>} Resolves to true if the panel was hidden, false if prevented.
672+
* Requests this panel's tab to close, invoking the registered
673+
* onCloseRequested handler first (if any). If the handler returns false,
674+
* the tab stays open. Otherwise, `closeTab()` is called.
675+
* @return {Promise<boolean>} Resolves to true if the tab was closed, false if prevented.
676676
*/
677677
Panel.prototype.requestClose = async function () {
678678
if (this._onCloseRequestedHandler) {
@@ -681,7 +681,7 @@ define(function (require, exports, module) {
681681
return false;
682682
}
683683
}
684-
this.hide({ preferFallback: true });
684+
this.closeTab();
685685
return true;
686686
};
687687

@@ -745,14 +745,17 @@ define(function (require, exports, module) {
745745
};
746746

747747
/**
748-
* Hides the panel
748+
* Hides this panel: removes its tab from the tab bar, and if this was
749+
* the active tab, collapses the bottom panel container. The panel stays
750+
* registered — call show() to bring it back.
751+
*
752+
* For tab-bar UX where closing the active tab should switch to the next
753+
* sibling tab (like clicking the X on a tab), use closeTab() instead.
754+
* For permanent removal, use destroy().
749755
*/
750-
Panel.prototype.hide = function (options) {
756+
Panel.prototype.hide = function () {
751757
let panelId = this.panelID;
752-
let preferFallback = !!(options && options.preferFallback);
753758

754-
// Quick Access panel is pinned — it stays in _openIds and the tab bar.
755-
// Hiding it collapses the bottom panel container entirely.
756759
if (panelId === _defaultPanelId) {
757760
if (_activeId !== panelId) {
758761
return;
@@ -773,16 +776,51 @@ define(function (require, exports, module) {
773776
return;
774777
}
775778

776-
// Remove from open set
779+
_openIds.splice(idx, 1);
780+
this.$panel.removeClass("active-bottom-panel");
781+
782+
if (_activeId === panelId) {
783+
_activeId = null;
784+
if (_$container) {
785+
restoreIfMaximized();
786+
Resizer.hide(_$container[0]);
787+
}
788+
}
789+
790+
_removeTabFromBar(panelId);
791+
792+
exports.trigger(EVENT_PANEL_HIDDEN, panelId);
793+
};
794+
795+
/**
796+
* Closes this tab: removes its tab from the tab bar. If this was the
797+
* active tab, switches to the next sibling tab; if no other tab is open,
798+
* collapses the bottom panel container instead. The panel stays
799+
* registered — call show() to bring it back.
800+
*
801+
* For a programmatic hide that always collapses (no auto-switch to a
802+
* sibling tab), use hide(). For permanent removal, use destroy().
803+
*/
804+
Panel.prototype.closeTab = function () {
805+
let panelId = this.panelID;
806+
807+
if (panelId === _defaultPanelId) {
808+
return;
809+
}
810+
811+
let idx = _openIds.indexOf(panelId);
812+
if (idx === -1) {
813+
return;
814+
}
815+
777816
_openIds.splice(idx, 1);
778817
this.$panel.removeClass("active-bottom-panel");
779818

780819
let wasActive = (_activeId === panelId);
781820
let activatedId = null;
782-
783821
let onlyDefaultLeft = (_openIds.length === 1 && _openIds[0] === _defaultPanelId);
784822

785-
if (wasActive && preferFallback && _openIds.length > 0 && !onlyDefaultLeft) {
823+
if (wasActive && _openIds.length > 0 && !onlyDefaultLeft) {
786824
let nextIdx = Math.min(idx, _openIds.length - 1);
787825
activatedId = _openIds[nextIdx];
788826
_activeId = null;

0 commit comments

Comments
 (0)