mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 19:09:59 +02:00
Merge pull request #60 from kristijanribaric/fix/create-new-tab-when-closing-last-unpinned-tab
Fix: Create new tab when closing last unpinned tab.
This commit is contained in:
commit
7a8579c913
2 changed files with 25 additions and 9 deletions
|
@ -184,7 +184,14 @@
|
||||||
filter: tab => !tab.hidden && !tab.pinned,
|
filter: tab => !tab.hidden && !tab.pinned,
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextTab = findNextTab(1) || findNextTab(-1);
|
let nextTab = findNextTab(1) || findNextTab(-1);
|
||||||
|
|
||||||
|
if (!nextTab) {
|
||||||
|
ZenWorkspaces._createNewTabForWorkspace({ uuid: ZenWorkspaces.activeWorkspace });
|
||||||
|
|
||||||
|
nextTab = findNextTab(1) || findNextTab(-1);
|
||||||
|
}
|
||||||
|
|
||||||
if (nextTab) {
|
if (nextTab) {
|
||||||
gBrowser.selectedTab = nextTab;
|
gBrowser.selectedTab = nextTab;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,9 +172,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
let tab = event.target;
|
let tab = event.target;
|
||||||
let workspaceID = tab.getAttribute('zen-workspace-id');
|
let workspaceID = tab.getAttribute('zen-workspace-id');
|
||||||
// If the tab is the last one in the workspace, create a new tab
|
// If the tab is the last unpinned one in the workspace, create a new tab
|
||||||
if (workspaceID) {
|
if (workspaceID) {
|
||||||
let tabs = gBrowser.tabs.filter((tab) => tab.getAttribute('zen-workspace-id') === workspaceID);
|
let tabs = gBrowser.tabs.filter((tab) => tab.getAttribute('zen-workspace-id') === workspaceID && !tab.pinned);
|
||||||
if (tabs.length === 1) {
|
if (tabs.length === 1) {
|
||||||
this._createNewTabForWorkspace({ uuid: workspaceID });
|
this._createNewTabForWorkspace({ uuid: workspaceID });
|
||||||
// We still need to close other tabs in the workspace
|
// We still need to close other tabs in the workspace
|
||||||
|
@ -697,8 +697,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
|
|
||||||
_createNewTabForWorkspace(window) {
|
_createNewTabForWorkspace(window) {
|
||||||
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
|
let tab = gZenUIManager.openAndChangeToTab(Services.prefs.getStringPref('browser.startup.homepage'));
|
||||||
|
|
||||||
|
if(window.uuid){
|
||||||
tab.setAttribute('zen-workspace-id', window.uuid);
|
tab.setAttribute('zen-workspace-id', window.uuid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async saveWorkspaceFromCreate() {
|
async saveWorkspaceFromCreate() {
|
||||||
let workspaceName = this._workspaceCreateInput.value;
|
let workspaceName = this._workspaceCreateInput.value;
|
||||||
|
@ -774,7 +777,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
(tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) ||
|
(tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) ||
|
||||||
!tab.hasAttribute('zen-workspace-id')
|
!tab.hasAttribute('zen-workspace-id')
|
||||||
) {
|
) {
|
||||||
if (!firstTab) {
|
if (!firstTab && (onInit || !tab.pinned)) {
|
||||||
firstTab = tab;
|
firstTab = tab;
|
||||||
} else if (gBrowser.selectedTab === tab) {
|
} else if (gBrowser.selectedTab === tab) {
|
||||||
// If the selected tab is already in the workspace, we don't want to change it
|
// If the selected tab is already in the workspace, we don't want to change it
|
||||||
|
@ -1026,12 +1029,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.shouldForceContainerTabsToWorkspace && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) {
|
if (this.shouldForceContainerTabsToWorkspace && typeof userContextId !== 'undefined' && this._workspaceCache?.workspaces) {
|
||||||
const workspace = this._workspaceCache.workspaces.find((workspace) => workspace.containerTabId === userContextId);
|
// Find all workspaces that match the given userContextId
|
||||||
if (workspace && workspace.uuid !== this.getActiveWorkspaceFromCache().uuid) {
|
const matchingWorkspaces = this._workspaceCache.workspaces.filter((workspace) => workspace.containerTabId === userContextId);
|
||||||
|
|
||||||
|
// Check if exactly one workspace matches
|
||||||
|
if (matchingWorkspaces.length === 1) {
|
||||||
|
const workspace = matchingWorkspaces[0];
|
||||||
|
if (workspace.uuid !== this.getActiveWorkspaceFromCache().uuid) {
|
||||||
this.changeWorkspace(workspace);
|
this.changeWorkspace(workspace);
|
||||||
return [userContextId, true];
|
return [userContextId, true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
||||||
const activeWorkspaceUserContextId = activeWorkspace?.containerTabId;
|
const activeWorkspaceUserContextId = activeWorkspace?.containerTabId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue