mirror of
https://github.com/zen-browser/components.git
synced 2025-07-10 05:05:29 +02:00
feat: Remember the last selected tab when cycling between workspaces
This commit is contained in:
parent
82814b4c9a
commit
569127a141
1 changed files with 15 additions and 1 deletions
|
@ -1,4 +1,9 @@
|
|||
var ZenWorkspaces = {
|
||||
/**
|
||||
* Stores workspace IDs and their last selected tabs.
|
||||
*/
|
||||
_lastSelectedWorkspaceTabs: {},
|
||||
|
||||
async init() {
|
||||
let docElement = document.documentElement;
|
||||
if (
|
||||
|
@ -166,6 +171,7 @@ var ZenWorkspaces = {
|
|||
console.info('ZenWorkspaces: Removing workspace', windowID);
|
||||
await this.changeWorkspace(json.workspaces.find((workspace) => workspace.uuid !== windowID));
|
||||
this._deleteAllTabsInWorkspace(windowID);
|
||||
delete this._lastSelectedWorkspaceTabs[windowID];
|
||||
json.workspaces = json.workspaces.filter((workspace) => workspace.uuid !== windowID);
|
||||
await this.unsafeSaveWorkspaces(json);
|
||||
await this._propagateWorkspaceData();
|
||||
|
@ -497,7 +503,7 @@ var ZenWorkspaces = {
|
|||
}
|
||||
}
|
||||
if (firstTab) {
|
||||
gBrowser.selectedTab = firstTab;
|
||||
gBrowser.selectedTab = this._lastSelectedWorkspaceTabs[window.uuid] ?? firstTab;
|
||||
}
|
||||
if (typeof firstTab === 'undefined' && !onInit) {
|
||||
this._createNewTabForWorkspace(window);
|
||||
|
@ -567,7 +573,9 @@ var ZenWorkspaces = {
|
|||
return;
|
||||
}
|
||||
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
|
||||
workspaceID = activeWorkspace.uuid;
|
||||
}
|
||||
this._lastSelectedWorkspaceTabs[workspaceID] = tab;
|
||||
},
|
||||
|
||||
// Context menu management
|
||||
|
@ -673,8 +681,14 @@ var ZenWorkspaces = {
|
|||
|
||||
async changeTabWorkspace(workspaceID) {
|
||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
const previousWorkspaceID = document.documentElement.getAttribute('zen-workspace-id');
|
||||
for (let tab of tabs) {
|
||||
tab.setAttribute('zen-workspace-id', workspaceID);
|
||||
if (this._lastSelectedWorkspaceTabs[previousWorkspaceID] === tab) {
|
||||
// This tab is no longer the last selected tab in the previous workspace because it's being moved to
|
||||
// the current workspace
|
||||
delete this._lastSelectedWorkspaceTabs[previousWorkspaceID];
|
||||
}
|
||||
}
|
||||
const workspaces = await this._workspaces();
|
||||
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue