Skip to content

Commit

Permalink
Workspace switching animations are now context aware
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Jan 11, 2025
1 parent 097404b commit 1f43997
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/browser/base/zen-components/ZenWorkspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
activeWorkspace = workspaces.workspaces[0];
this.activeWorkspace = activeWorkspace?.uuid;
}
await this.changeWorkspace(activeWorkspace, true);
await this.changeWorkspace(activeWorkspace, { onInit: true });
}
try {
if (activeWorkspace) {
Expand Down Expand Up @@ -1267,22 +1267,22 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._changeListeners.push(func);
}

async changeWorkspace(window, onInit = false) {
async changeWorkspace(window, ...args) {
if (!this.workspaceEnabled || this._inChangingWorkspace) {
return;
}

await SessionStore.promiseInitialized;
this._inChangingWorkspace = true;
try {
await this._performWorkspaceChange(window, onInit);
await this._performWorkspaceChange(window, ...args);
} finally {
this._inChangingWorkspace = false;
this.tabContainer.removeAttribute('dont-animate-tabs');
}
}

async _performWorkspaceChange(window, onInit) {
async _performWorkspaceChange(window, { onInit = false, explicitAnimationDirection = undefined } = {}) {
const previousWorkspace = await this.getActiveWorkspace();

this.activeWorkspace = window.uuid;
Expand All @@ -1294,10 +1294,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {

let animationDirection;
if (previousWorkspace && !onInit && !this._animatingChange) {
animationDirection = (
workspaces.workspaces.findIndex((w) => w.uuid === previousWorkspace.uuid) <
animationDirection =
explicitAnimationDirection ??
(workspaces.workspaces.findIndex((w) => w.uuid === previousWorkspace.uuid) <
workspaces.workspaces.findIndex((w) => w.uuid === window.uuid)
) ? 'right' : 'left';
? 'right'
: 'left');
}
if (animationDirection) {
// Animate tabs out of view before changing workspace, therefor we
Expand Down Expand Up @@ -1332,10 +1334,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.tabContainer.removeAttribute('dont-animate-tabs');
if (out) {
for (let tab of tabs) {
tab.animate([
{ transform: 'translateX(0)' },
{ transform: `translateX(${direction === 'left' ? '-' : ''}100%)` },
], {
tab.animate([{ transform: 'translateX(0)' }, { transform: `translateX(${direction === 'left' ? '-' : ''}100%)` }], {
duration: 150,
easing: 'ease',
fill: 'both',
Expand All @@ -1344,10 +1343,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return;
}
for (let tab of tabs) {
tab.animate([
{ transform: `translateX(${direction === 'left' ? '-' : ''}100%)` },
{ transform: 'translateX(0)' },
], {
tab.animate([{ transform: `translateX(${direction === 'left' ? '-' : ''}100%)` }, { transform: 'translateX(0)' }], {
duration: 150,
easing: 'ease',
fill: 'both',
Expand Down Expand Up @@ -1721,7 +1717,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}

let nextWorkspace = workspaces.workspaces[targetIndex];
await this.changeWorkspace(nextWorkspace);
await this.changeWorkspace(nextWorkspace, { explicitAnimationDirection: offset > 0 ? 'right' : 'left' });
}

_initializeWorkspaceTabContextMenus() {
Expand Down

0 comments on commit 1f43997

Please sign in to comment.