Fixed switching workspaces with

This commit is contained in:
mr. m
2025-02-11 23:27:43 +01:00
parent 2c9358ca07
commit c4b4aa6287

View File

@@ -384,7 +384,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
let rawDirection = moveForward ? 1 : -1; let rawDirection = moveForward ? 1 : -1;
if (this._swipeState.direction) { if (this._swipeState.direction) {
let direction = this.naturalScroll ? -1 : 1; let direction = this.naturalScroll ? -1 : 1;
this.changeWorkspaceShortcut(rawDirection * direction); this.changeWorkspaceShortcut(rawDirection * direction, true);
} else { } else {
this._cancelSwipeAnimation(); this._cancelSwipeAnimation();
} }
@@ -1412,7 +1412,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._animateTabs({ uuid: currentWorkspace }, true); this._animateTabs({ uuid: currentWorkspace }, true);
} }
async _performWorkspaceChange(window, { onInit = false, alwaysChange = false, explicitAnimationDirection = undefined } = {}) { async _performWorkspaceChange(window, { onInit = false, alwaysChange = false, whileScrolling = false } = {}) {
const previousWorkspace = await this.getActiveWorkspace(); const previousWorkspace = await this.getActiveWorkspace();
alwaysChange = alwaysChange || onInit; alwaysChange = alwaysChange || onInit;
@@ -1429,7 +1429,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
gBrowser.verticalPinnedTabsContainer = this.pinnedTabsContainer; gBrowser.verticalPinnedTabsContainer = this.pinnedTabsContainer;
gBrowser.tabContainer.verticalPinnedTabsContainer = this.pinnedTabsContainer; gBrowser.tabContainer.verticalPinnedTabsContainer = this.pinnedTabsContainer;
this.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
if (!whileScrolling) {
await this._organizeWorkspaceStripLocations(previousWorkspace); await this._organizeWorkspaceStripLocations(previousWorkspace);
}
// First pass: Handle tab visibility and workspace ID assignment // First pass: Handle tab visibility and workspace ID assignment
this._processTabVisibility(window.uuid, containerId, workspaces); this._processTabVisibility(window.uuid, containerId, workspaces);
@@ -1459,8 +1461,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const selector = `.zen-workspace-tabs-section[zen-workspace-id="${otherWorkspace.uuid}"]`; const selector = `.zen-workspace-tabs-section[zen-workspace-id="${otherWorkspace.uuid}"]`;
const newTransform = -(workspaceIndex - workspaces.workspaces.indexOf(otherWorkspace)) * 100; const newTransform = -(workspaceIndex - workspaces.workspaces.indexOf(otherWorkspace)) * 100;
for (const container of document.querySelectorAll(selector)) { for (const container of document.querySelectorAll(selector)) {
container.style.transform = `translateX(calc(${newTransform}% + ${offsetPixels}px))`; container.style.transform = `translateX(${newTransform + offsetPixels / 2}%)`;
container.style.opacity = !newTransform; container.style.opacity = offsetPixels ? 1 : !newTransform;
} }
if (!justMove) { if (!justMove) {
const pinnedContainerId = '#vertical-pinned-tabs-container '; const pinnedContainerId = '#vertical-pinned-tabs-container ';
@@ -1508,14 +1510,18 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const elementWorkspaceIndex = workspaces.workspaces.findIndex((w) => w.uuid === elementWorkspaceId); const elementWorkspaceIndex = workspaces.workspaces.findIndex((w) => w.uuid === elementWorkspaceId);
const offset = -(newWorkspaceIndex - elementWorkspaceIndex) * 100; const offset = -(newWorkspaceIndex - elementWorkspaceIndex) * 100;
const newTransform = `translateX(${offset}%)`; const newTransform = `translateX(${offset}%)`;
const isCurrent = offset === 0;
if (shouldAnimate) { if (shouldAnimate) {
if (isCurrent) {
element.style.opacity = 1;
}
animations.push( animations.push(
gZenUIManager.motion.animate( gZenUIManager.motion.animate(
element, element,
{ {
transform: existingTransform ? [existingTransform, newTransform] : newTransform, transform: existingTransform ? [existingTransform, newTransform] : newTransform,
// -0 to convert to number // -0 to convert to number
opacity: [!!offset - 0, !offset - 0], opacity: !isCurrent ? [!!offset - 0, !offset - 0] : [1, 1],
}, },
{ {
type: 'spring', type: 'spring',
@@ -1532,6 +1538,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
} }
await Promise.all(animations); await Promise.all(animations);
if (this._beforeSelectedTab) {
this._beforeSelectedTab._visuallySelected = false;
this._beforeSelectedTab = null;
}
this._animatingChange = false; this._animatingChange = false;
} }
@@ -1614,6 +1624,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
gBrowser.selectedTab = newTab; gBrowser.selectedTab = newTab;
this._lastSelectedWorkspaceTabs[window.uuid] = newTab; this._lastSelectedWorkspaceTabs[window.uuid] = newTab;
} }
// Always make sure we always unselect the tab from the old workspace
currentSelectedTab._selected = false;
currentSelectedTab._visuallySelected = true; // we do want to animate the tab deselection
this._beforeSelectedTab = currentSelectedTab;
} }
async _updateWorkspaceState(window, onInit) { async _updateWorkspaceState(window, onInit) {
@@ -1880,7 +1894,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._emojis = null; this._emojis = null;
} }
async changeWorkspaceShortcut(offset = 1) { async changeWorkspaceShortcut(offset = 1, whileScrolling = false) {
// Cycle through workspaces // Cycle through workspaces
let workspaces = await this._workspaces(); let workspaces = await this._workspaces();
let activeWorkspace = await this.getActiveWorkspace(); let activeWorkspace = await this.getActiveWorkspace();
@@ -1897,7 +1911,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
let nextWorkspace = workspaces.workspaces[targetIndex]; let nextWorkspace = workspaces.workspaces[targetIndex];
await this.changeWorkspace(nextWorkspace, { explicitAnimationDirection: offset > 0 ? 'right' : 'left' }); await this.changeWorkspace(nextWorkspace, { whileScrolling });
} }
_initializeWorkspaceTabContextMenus() { _initializeWorkspaceTabContextMenus() {