Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions docs/API-Reference/view/PanelView.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Preference key for persisting the maximize state across reloads.
* [.show()](#Panel+show)
* [.addToTabBar()](#Panel+addToTabBar)
* [.hide()](#Panel+hide)
* [.closeTab()](#Panel+closeTab)
* [.focus()](#Panel+focus) ⇒ <code>boolean</code>
* [.setVisible(visible)](#Panel+setVisible)
* [.setTitle(newTitle)](#Panel+setTitle)
Expand Down Expand Up @@ -196,12 +197,12 @@ tab close button). The handler should return `true` to allow the close, or `fals
<a name="Panel+requestClose"></a>

### panel.requestClose() ⇒ <code>Promise.&lt;boolean&gt;</code>
Requests the panel to hide, invoking the registered onCloseRequested handler first (if any).
If the handler returns false, the panel stays open. If it returns true or no handler is
registered, `hide()` is called.
Requests this panel's tab to close, invoking the registered
onCloseRequested handler first (if any). If the handler returns false,
the tab stays open. Otherwise, `closeTab()` is called.

**Kind**: instance method of [<code>Panel</code>](#Panel)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - Resolves to true if the panel was hidden, false if prevented.
**Returns**: <code>Promise.&lt;boolean&gt;</code> - Resolves to true if the tab was closed, false if prevented.
<a name="Panel+show"></a>

### panel.show()
Expand All @@ -219,7 +220,25 @@ was collapsed by the user — avoids forcing the bottom panel open.
<a name="Panel+hide"></a>

### panel.hide()
Hides the panel
Hides this panel: removes its tab from the tab bar, and if this was
the active tab, collapses the bottom panel container. The panel stays
registered — call show() to bring it back.

For tab-bar UX where closing the active tab should switch to the next
sibling tab (like clicking the X on a tab), use closeTab() instead.
For permanent removal, use destroy().

**Kind**: instance method of [<code>Panel</code>](#Panel)
<a name="Panel+closeTab"></a>

### panel.closeTab()
Closes this tab: removes its tab from the tab bar. If this was the
active tab, switches to the next sibling tab; if no other tab is open,
collapses the bottom panel container instead. The panel stays
registered — call show() to bring it back.

For a programmatic hide that always collapses (no auto-switch to a
sibling tab), use hide(). For permanent removal, use destroy().

**Kind**: instance method of [<code>Panel</code>](#Panel)
<a name="Panel+focus"></a>
Expand Down
61 changes: 51 additions & 10 deletions src/view/PanelView.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ define(function (require, exports, module) {
};

/**
* Requests the panel to hide, invoking the registered onCloseRequested handler first (if any).
* If the handler returns false, the panel stays open. If it returns true or no handler is
* registered, `hide()` is called.
* @return {Promise<boolean>} Resolves to true if the panel was hidden, false if prevented.
* Requests this panel's tab to close, invoking the registered
* onCloseRequested handler first (if any). If the handler returns false,
* the tab stays open. Otherwise, `closeTab()` is called.
* @return {Promise<boolean>} Resolves to true if the tab was closed, false if prevented.
*/
Panel.prototype.requestClose = async function () {
if (this._onCloseRequestedHandler) {
Expand All @@ -681,7 +681,7 @@ define(function (require, exports, module) {
return false;
}
}
this.hide();
this.closeTab();
return true;
};

Expand Down Expand Up @@ -745,13 +745,17 @@ define(function (require, exports, module) {
};

/**
* Hides the panel
* Hides this panel: removes its tab from the tab bar, and if this was
* the active tab, collapses the bottom panel container. The panel stays
* registered — call show() to bring it back.
*
* For tab-bar UX where closing the active tab should switch to the next
* sibling tab (like clicking the X on a tab), use closeTab() instead.
* For permanent removal, use destroy().
*/
Panel.prototype.hide = function () {
let panelId = this.panelID;

// Quick Access panel is pinned — it stays in _openIds and the tab bar.
// Hiding it collapses the bottom panel container entirely.
if (panelId === _defaultPanelId) {
if (_activeId !== panelId) {
return;
Expand All @@ -772,14 +776,51 @@ define(function (require, exports, module) {
return;
}

// Remove from open set
_openIds.splice(idx, 1);
this.$panel.removeClass("active-bottom-panel");

if (_activeId === panelId) {
_activeId = null;
if (_$container) {
restoreIfMaximized();
Resizer.hide(_$container[0]);
}
}

_removeTabFromBar(panelId);

exports.trigger(EVENT_PANEL_HIDDEN, panelId);
};

/**
* Closes this tab: removes its tab from the tab bar. If this was the
* active tab, switches to the next sibling tab; if no other tab is open,
* collapses the bottom panel container instead. The panel stays
* registered — call show() to bring it back.
*
* For a programmatic hide that always collapses (no auto-switch to a
* sibling tab), use hide(). For permanent removal, use destroy().
*/
Panel.prototype.closeTab = function () {
let panelId = this.panelID;

if (panelId === _defaultPanelId) {
return;
}

let idx = _openIds.indexOf(panelId);
if (idx === -1) {
return;
}

_openIds.splice(idx, 1);
this.$panel.removeClass("active-bottom-panel");

let wasActive = (_activeId === panelId);
let activatedId = null;
let onlyDefaultLeft = (_openIds.length === 1 && _openIds[0] === _defaultPanelId);

if (wasActive && _openIds.length > 0) {
if (wasActive && _openIds.length > 0 && !onlyDefaultLeft) {
let nextIdx = Math.min(idx, _openIds.length - 1);
activatedId = _openIds[nextIdx];
_activeId = null;
Expand Down
2 changes: 1 addition & 1 deletion src/view/WorkspaceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ define(function (require, exports, module) {
// buttons and menu items that mirror container visibility
// (drawer, Git icon, etc.) need this signal to deselect.
PanelView.collapseContainer();
} else if (PanelView.getOpenBottomPanelIDs().length > 0) {
} else if (PanelView.getActiveBottomPanel()) {
// Use the helper so SHOWN(_activeId) fires — same listeners
// need this signal to re-select after a previous collapse.
PanelView.restoreContainer();
Expand Down
Loading