mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 15:39:58 +02:00
Fix: Open new tab when last unpinned tab is closed in workspace and no pinned tabs are loaded
Added a preference to keep default behavior or apply the new one.
This commit is contained in:
parent
e04d67db05
commit
b77d7ce110
1 changed files with 35 additions and 13 deletions
|
@ -25,6 +25,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
'zen.workspaces.force-container-workspace',
|
'zen.workspaces.force-container-workspace',
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
|
this,
|
||||||
|
'shouldOpenNewTabIfLastUnpinnedTabIsClosed',
|
||||||
|
'zen.workspaces.open-new-tab-if-last-unpinned-tab-is-closed',
|
||||||
|
false
|
||||||
|
);
|
||||||
ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs'));
|
ChromeUtils.defineLazyGetter(this, 'tabContainer', () => document.getElementById('tabbrowser-tabs'));
|
||||||
this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', '');
|
this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||||
await ZenWorkspacesStorage.init();
|
await ZenWorkspacesStorage.init();
|
||||||
|
@ -145,7 +151,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
if (this.workspaceEnabled) {
|
if (this.workspaceEnabled) {
|
||||||
this._initializeWorkspaceCreationIcons();
|
this._initializeWorkspaceCreationIcons();
|
||||||
this._initializeWorkspaceTabContextMenus();
|
this._initializeWorkspaceTabContextMenus();
|
||||||
window.addEventListener('TabClose', this.handleTabClose.bind(this));
|
|
||||||
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
|
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
|
||||||
let workspaces = await this._workspaces();
|
let workspaces = await this._workspaces();
|
||||||
if (workspaces.workspaces.length === 0) {
|
if (workspaces.workspaces.length === 0) {
|
||||||
|
@ -166,21 +171,38 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTabClose(event) {
|
handleTabBeforeClose(tab) {
|
||||||
if (this.__contextIsDelete) {
|
if (!this.workspaceEnabled || this.__contextIsDelete) {
|
||||||
return; // Bug when closing tabs from the context menu
|
return null;
|
||||||
}
|
}
|
||||||
let tab = event.target;
|
|
||||||
let workspaceID = tab.getAttribute('zen-workspace-id');
|
let workspaceID = tab.getAttribute('zen-workspace-id');
|
||||||
// If the tab is the last unpinned one in the workspace, create a new tab
|
if (!workspaceID) {
|
||||||
if (workspaceID) {
|
return null;
|
||||||
let tabs = gBrowser.tabs.filter((tab) => tab.getAttribute('zen-workspace-id') === workspaceID && !tab.pinned);
|
|
||||||
if (tabs.length === 1) {
|
|
||||||
this._createNewTabForWorkspace({ uuid: workspaceID });
|
|
||||||
// We still need to close other tabs in the workspace
|
|
||||||
this.changeWorkspace({ uuid: workspaceID }, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shouldOpenNewTabIfLastUnpinnedTabIsClosed = this.shouldOpenNewTabIfLastUnpinnedTabIsClosed;
|
||||||
|
|
||||||
|
let tabs = gBrowser.tabs.filter(t =>
|
||||||
|
t.getAttribute('zen-workspace-id') === workspaceID &&
|
||||||
|
(!shouldOpenNewTabIfLastUnpinnedTabIsClosed ||!t.pinned || t.getAttribute("pending") !== "true")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (tabs.length === 1 && tabs[0] === tab) {
|
||||||
|
let newTab = this._createNewTabForWorkspace({ uuid: workspaceID });
|
||||||
|
return newTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_createNewTabForWorkspace(window) {
|
||||||
|
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
|
||||||
|
|
||||||
|
if(window.uuid){
|
||||||
|
tab.setAttribute('zen-workspace-id', window.uuid);
|
||||||
|
}
|
||||||
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
_kIcons = JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) =>
|
_kIcons = JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue