Bug 1939599: Tab groups can be restored by Ctrl+Shift+T r=dao,sthompson,sessionstore-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D233102
This commit is contained in:
Jeremy Swinarton
2025-01-08 22:33:13 +00:00
parent 82f19238e9
commit cf0ea617df
4 changed files with 132 additions and 11 deletions

View File

@@ -237,6 +237,10 @@ export var SessionStore = {
return SessionStoreInternal._LAST_ACTION_CLOSED_TAB;
},
get LAST_ACTION_CLOSED_TAB_GROUP() {
return SessionStoreInternal._LAST_ACTION_CLOSED_TAB_GROUP;
},
get LAST_ACTION_CLOSED_WINDOW() {
return SessionStoreInternal._LAST_ACTION_CLOSED_WINDOW;
},
@@ -1047,6 +1051,8 @@ var SessionStoreInternal = {
_LAST_ACTION_CLOSED_TAB: "tab",
_LAST_ACTION_CLOSED_TAB_GROUP: "tab-group",
_LAST_ACTION_CLOSED_WINDOW: "window",
_log: null,
@@ -3046,6 +3052,15 @@ var SessionStoreInternal = {
win,
tabGroup
) {
// don't update our internal state if we don't have to
if (this._max_tabs_undo == 0) {
return;
}
// Record the closed action right away to make sure it's also being
// recorded for groups that are saved and closed
this._addClosedAction(this._LAST_ACTION_CLOSED_TAB_GROUP, tabGroup.id);
if (this.getSavedTabGroup(tabGroup.id)) {
// If a tab group is being removed from the tab strip but it's already
// saved, then this is a "save and close" action; the saved tab group
@@ -3054,24 +3069,17 @@ var SessionStoreInternal = {
return;
}
// don't update our internal state if we don't have to
if (this._max_tabs_undo == 0) {
return;
}
let closedGroups = this._windows[win.__SSi].closedGroups;
let tabGroupState = lazy.TabGroupState.closed(tabGroup, win.__SSi);
tabGroupState.tabs = this._collectClosedTabsForTabGroup(tabGroup.tabs, win);
// TODO(jswinarton) it's unclear if updating lastClosedTabGroupCount is
// necessary when restoring tab groups — it largely depends on how we
// decide to do the restore. If we add a _LAST_ACTION_CLOSED_TAB_GROUP
// item to the closed actions list, this may not be necessary.
// decide to do the restore.
// To address in bug1915174
this._windows[win.__SSi]._lastClosedTabGroupCount =
tabGroupState.tabs.length;
closedGroups.push(tabGroupState);
closedGroups.unshift(tabGroupState);
this._closedObjectsChanged = true;
},
@@ -3312,8 +3320,16 @@ var SessionStoreInternal = {
* The tabData to be inserted.
* @param closedTabs (array)
* The list of closed tabs for a window.
* @param saveAction (boolean|null)
* Whether or not to add an action to the closed actions stack on save.
* True by default if the tab was not closed as part of a tab group; false otherwise.
*/
saveClosedTabData(winData, closedTabs, tabData, saveAction = true) {
saveClosedTabData(winData, closedTabs, tabData, saveAction = null) {
if (saveAction === null) {
// By default, a closed action for this tab, but only if it wasn't closed as part of a tab group.
saveAction = closedTabs === winData._closedTabs;
}
// Find the index of the first tab in the list
// of closed tabs that was closed before our tab.
let index = closedTabs.findIndex(tab => {
@@ -4128,7 +4144,7 @@ var SessionStoreInternal = {
if (
groupIdx < closedGroups.length &&
(tabIdx >= closedTabs.length || group?.closedAt < tab?.closedAt)
(tabIdx >= closedTabs.length || group?.closedAt > tab?.closedAt)
) {
group.tabs.forEach((groupTab, idx) => {
groupTab._originalStateIndex = idx;