mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:09:58 +02:00
refactor: Add event listener for tab close in ZenWorkspaces
This commit adds an event listener for the "TabClose" event in the ZenWorkspaces module. When a tab is closed, the listener checks if it is the last tab in a workspace and creates a new tab if necessary. It also closes other tabs in the workspace. This enhancement improves the functionality and user experience of ZenWorkspaces.
This commit is contained in:
parent
7bf34b6f28
commit
2ef396ee87
1 changed files with 15 additions and 0 deletions
|
@ -56,6 +56,7 @@ var ZenWorkspaces = {
|
||||||
await IOUtils.writeJSON(this._storeFile, {});
|
await IOUtils.writeJSON(this._storeFile, {});
|
||||||
}
|
}
|
||||||
if (this.workspaceEnabled) {
|
if (this.workspaceEnabled) {
|
||||||
|
window.addEventListener("TabClose", this.handleTabClose.bind(this));
|
||||||
let workspaces = await this._workspaces();
|
let workspaces = await this._workspaces();
|
||||||
if (workspaces.workspaces.length === 0) {
|
if (workspaces.workspaces.length === 0) {
|
||||||
await this.createAndSaveWorkspace("Default Workspace", true);
|
await this.createAndSaveWorkspace("Default Workspace", true);
|
||||||
|
@ -80,6 +81,20 @@ var ZenWorkspaces = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleTabClose(event) {
|
||||||
|
let tab = event.target;
|
||||||
|
let workspaceID = tab.getAttribute("zen-workspace-id");
|
||||||
|
// If the tab is the last one in the workspace, create a new tab
|
||||||
|
if (workspaceID) {
|
||||||
|
let tabs = gBrowser.tabs.filter(tab => tab.getAttribute("zen-workspace-id") === workspaceID);
|
||||||
|
if (tabs.length === 1) {
|
||||||
|
this._createNewTabForWorkspace({ uuid: workspaceID });
|
||||||
|
// We still need to close other tabs in the workspace
|
||||||
|
this.changeWorkspace({ uuid: workspaceID });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_initializeWorkspaceIcons() {
|
_initializeWorkspaceIcons() {
|
||||||
const kIcons = ["🏠", "📄", "💹", "💼", "📧", "✅", "👥"];
|
const kIcons = ["🏠", "📄", "💹", "💼", "📧", "✅", "👥"];
|
||||||
let container = document.getElementById("PanelUI-zen-workspaces-create-icons-container");
|
let container = document.getElementById("PanelUI-zen-workspaces-create-icons-container");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue