Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue with mouse 4 / 5 buttons and added wrap pref to shortcuts… #4027

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 26 additions & 55 deletions src/browser/base/zen-components/ZenWorkspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return;
}

const direction = this.naturalScroll ? -1 : 1;
// event is forward or back
switch (event.command) {
case "Forward":
this.changeWorkspaceShortcut(1);
this.changeWorkspaceShortcut(1 * direction);
event.stopImmediatePropagation();
event.preventDefault();
break;
case "Back":
this.changeWorkspaceShortcut(-1);
this.changeWorkspaceShortcut(-1 * direction);
event.stopImmediatePropagation();
event.preventDefault();
break;
Expand Down Expand Up @@ -177,29 +179,10 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (Math.abs(delta) < scrollThreshold) return;

// Determine scroll direction
let direction = delta > 0 ? 1 : -1;
if (this.naturalScroll) {
direction = delta > 0 ? -1 : 1;
}

// Workspace logic
const workspaces = (await this._workspaces()).workspaces;
const currentIndex = workspaces.findIndex(w => w.uuid === this.activeWorkspace);
if (currentIndex === -1) return; // No valid current workspace

let targetIndex = currentIndex + direction;
let rawDirection = delta > 0 ? 1 : -1;

if (this.shouldWrapAroundNavigation) {
// Add length to handle negative indices and loop
targetIndex = (targetIndex + workspaces.length) % workspaces.length;
} else {
// Clamp within bounds to disable looping
targetIndex = Math.max(0, Math.min(workspaces.length - 1, targetIndex));
}

if (targetIndex !== currentIndex) {
await this.changeWorkspace(workspaces[targetIndex]);
}
let direction = this.naturalScroll ? -1 : 1;
this.changeWorkspaceShortcut(rawDirection * direction);

this._lastScrollTime = currentTime;
}, { passive: true });
Expand Down Expand Up @@ -265,42 +248,21 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Determine swipe direction based on cumulative delta
if (Math.abs(this._swipeState.cumulativeDelta) > 0.25) {
this._swipeState.direction = this._swipeState.cumulativeDelta > 0 ? 'left' : 'right';
if (this.naturalScroll){
this._swipeState.direction = this._swipeState.cumulativeDelta > 0 ? 'right' : 'left';
}
}

}

async _handleSwipeEnd(event) {
if (!this.workspaceEnabled || !this._swipeState?.isGestureActive) return;
event.preventDefault();
event.stopPropagation();

const isRTL = document.documentElement.matches(':-moz-locale-dir(rtl)');
const moveForward = (this._swipeState.direction === 'right') !== isRTL;

let rawDirection = moveForward ? 1 : -1;
if (this._swipeState.direction) {
const workspaces = (await this._workspaces()).workspaces;
const currentIndex = workspaces.findIndex(w => w.uuid === this.activeWorkspace);

if (currentIndex !== -1) {
const isRTL = document.documentElement.matches(':-moz-locale-dir(rtl)');
const moveForward = (this._swipeState.direction === 'right') !== isRTL;

let targetIndex = moveForward
? currentIndex + 1
: currentIndex - 1;

if (this.shouldWrapAroundNavigation) {
// Add length to handle negative indices and clamp within bounds
targetIndex = (targetIndex + workspaces.length) % workspaces.length;
} else {
// Clamp within bounds for to remove looping
targetIndex = Math.max(0, Math.min(workspaces.length - 1, targetIndex));
}

if (targetIndex !== currentIndex) {
await this.changeWorkspace(workspaces[targetIndex]);
}
}

let direction = this.naturalScroll ? -1 : 1;
this.changeWorkspaceShortcut(rawDirection * direction);
}

// Reset swipe state
Expand Down Expand Up @@ -1575,14 +1537,23 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.openEditDialog(this._contextMenuId);
}

async changeWorkspaceShortcut(offset = 1) {
async changeWorkspaceShortcut(offset = 1){
// Cycle through workspaces
let workspaces = await this._workspaces();
let activeWorkspace = await this.getActiveWorkspace();
let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace);

// note: offset can be negative
let nextWorkspace =
workspaces.workspaces[(workspaceIndex + offset + workspaces.workspaces.length) % workspaces.workspaces.length];
let targetIndex = workspaceIndex + offset;
if (this.shouldWrapAroundNavigation) {
// Add length to handle negative indices and loop
targetIndex = (targetIndex + workspaces.workspaces.length) % workspaces.workspaces.length;
} else {
// Clamp within bounds to disable looping
targetIndex = Math.max(0, Math.min(workspaces.workspaces.length - 1, targetIndex));
}

let nextWorkspace = workspaces.workspaces[(targetIndex)];
await this.changeWorkspace(nextWorkspace);
}

Expand Down
Loading