mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 13:39:58 +02:00
Merge pull request #11 from jivanf/cycle-to-last-selected-workspace-tab
feat: Remember the last selected tab when cycling between workspaces
This commit is contained in:
commit
078f5ff992
1 changed files with 19 additions and 7 deletions
|
@ -1,5 +1,10 @@
|
||||||
|
|
||||||
var ZenWorkspaces = {
|
var ZenWorkspaces = {
|
||||||
|
/**
|
||||||
|
* Stores workspace IDs and their last selected tabs.
|
||||||
|
*/
|
||||||
|
_lastSelectedWorkspaceTabs: {},
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
let docElement = document.documentElement;
|
let docElement = document.documentElement;
|
||||||
if (
|
if (
|
||||||
|
@ -165,6 +170,7 @@ var ZenWorkspaces = {
|
||||||
console.info('ZenWorkspaces: Removing workspace', windowID);
|
console.info('ZenWorkspaces: Removing workspace', windowID);
|
||||||
await this.changeWorkspace(json.workspaces.find((workspace) => workspace.uuid !== windowID));
|
await this.changeWorkspace(json.workspaces.find((workspace) => workspace.uuid !== windowID));
|
||||||
this._deleteAllTabsInWorkspace(windowID);
|
this._deleteAllTabsInWorkspace(windowID);
|
||||||
|
delete this._lastSelectedWorkspaceTabs[windowID];
|
||||||
json.workspaces = json.workspaces.filter((workspace) => workspace.uuid !== windowID);
|
json.workspaces = json.workspaces.filter((workspace) => workspace.uuid !== windowID);
|
||||||
await this.unsafeSaveWorkspaces(json);
|
await this.unsafeSaveWorkspaces(json);
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
|
@ -242,8 +248,8 @@ var ZenWorkspaces = {
|
||||||
(container) => container.userContextId === workspace.containerTabId
|
(container) => container.userContextId === workspace.containerTabId
|
||||||
);
|
);
|
||||||
if (containerGroup) {
|
if (containerGroup) {
|
||||||
element.classList.add("identity-color-" + containerGroup.color);
|
element.classList.add('identity-color-' + containerGroup.color);
|
||||||
element.setAttribute("data-usercontextid", containerGroup.userContextId);
|
element.setAttribute('data-usercontextid', containerGroup.userContextId);
|
||||||
}
|
}
|
||||||
let childs = window.MozXULElement.parseXULToFragment(`
|
let childs = window.MozXULElement.parseXULToFragment(`
|
||||||
<div class="zen-workspace-icon">
|
<div class="zen-workspace-icon">
|
||||||
|
@ -501,7 +507,7 @@ var ZenWorkspaces = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (firstTab) {
|
if (firstTab) {
|
||||||
gBrowser.selectedTab = firstTab;
|
gBrowser.selectedTab = this._lastSelectedWorkspaceTabs[window.uuid] ?? firstTab;
|
||||||
}
|
}
|
||||||
if (typeof firstTab === 'undefined' && !onInit) {
|
if (typeof firstTab === 'undefined' && !onInit) {
|
||||||
this._createNewTabForWorkspace(window);
|
this._createNewTabForWorkspace(window);
|
||||||
|
@ -575,7 +581,9 @@ var ZenWorkspaces = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
|
tab.setAttribute('zen-workspace-id', activeWorkspace.uuid);
|
||||||
|
workspaceID = activeWorkspace.uuid;
|
||||||
}
|
}
|
||||||
|
this._lastSelectedWorkspaceTabs[workspaceID] = tab;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Context menu management
|
// Context menu management
|
||||||
|
@ -613,9 +621,7 @@ var ZenWorkspaces = {
|
||||||
async contextChangeContainerTab(event) {
|
async contextChangeContainerTab(event) {
|
||||||
let workspaces = await this._workspaces();
|
let workspaces = await this._workspaces();
|
||||||
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);
|
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);
|
||||||
let userContextId = parseInt(
|
let userContextId = parseInt(event.target.getAttribute('data-usercontextid'));
|
||||||
event.target.getAttribute("data-usercontextid")
|
|
||||||
);
|
|
||||||
workspace.containerTabId = userContextId;
|
workspace.containerTabId = userContextId;
|
||||||
await this.saveWorkspace(workspace);
|
await this.saveWorkspace(workspace);
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
|
@ -683,8 +689,14 @@ var ZenWorkspaces = {
|
||||||
|
|
||||||
async changeTabWorkspace(workspaceID) {
|
async changeTabWorkspace(workspaceID) {
|
||||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||||
|
const previousWorkspaceID = document.documentElement.getAttribute('zen-workspace-id');
|
||||||
for (let tab of tabs) {
|
for (let tab of tabs) {
|
||||||
tab.setAttribute('zen-workspace-id', workspaceID);
|
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();
|
const workspaces = await this._workspaces();
|
||||||
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
|
await this.changeWorkspace(workspaces.workspaces.find((workspace) => workspace.uuid === workspaceID));
|
||||||
|
@ -703,7 +715,7 @@ var ZenWorkspaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getContextIdIfNeeded(userContextId) {
|
getContextIdIfNeeded(userContextId) {
|
||||||
if (typeof userContextId !== "undefined" || !this.workspaceEnabled) {
|
if (typeof userContextId !== 'undefined' || !this.workspaceEnabled) {
|
||||||
return [userContextId, false];
|
return [userContextId, false];
|
||||||
}
|
}
|
||||||
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue