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

Feature: Add workspace switching by horizontally scrolling sidebar #2828

Merged
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
29 changes: 27 additions & 2 deletions src/browser/base/zen-components/ZenWorkspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
direction: null
};
_hoveringSidebar = false;
_lastScrollTime = 0;

async init() {
if (!this.shouldHaveWorkspaces) {
Expand Down Expand Up @@ -57,7 +58,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {

initializeWorkspaceNavigation() {
this._setupAppCommandHandlers();
this._setupHoverDetection();
this._setupSidebarHandlers();
}

_setupAppCommandHandlers() {
Expand Down Expand Up @@ -90,7 +91,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
}

_setupHoverDetection() {
_setupSidebarHandlers() {
const toolbox = document.getElementById('navigator-toolbox');

toolbox.addEventListener('mouseenter', () => {
Expand All @@ -100,6 +101,30 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
toolbox.addEventListener('mouseleave', () => {
this._hoveringSidebar = false;
});

const scrollCooldown = 500; // Milliseconds to wait before allowing another scroll
const scrollThreshold = 5; // Minimum scroll delta to trigger workspace change

toolbox.addEventListener('wheel', async (event) => {
if (!this.workspaceEnabled) return;
// Only process horizontal scroll (deltaX)
if (!event.deltaX) return;

const currentTime = Date.now();
if (currentTime - this._lastScrollTime < scrollCooldown) {
return;
}

// Only process if the horizontal scroll is significant enough
if (Math.abs(event.deltaX) < scrollThreshold) {
return;
}

// Change workspace based on scroll direction
const direction = event.deltaX > 0 ? -1 : 1;
await this.changeWorkspaceShortcut(direction);
this._lastScrollTime = currentTime;
}, { passive: true });
}

initializeGestureHandlers() {
Expand Down
Loading