Skip to content

Commit

Permalink
Add smooth scroll preference for tab startup and adjust visibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Jan 3, 2025
1 parent 32e9d6f commit d91c9dc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/browser/app/profile/zen-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pref('zen.splitView.min-resize-width', 7);
pref('zen.splitView.change-on-hover', false);
pref('zen.splitView.rearrange-hover-size', 24);

// Startup flags
pref('zen.startup.smooth-scroll-in-tabs', true);

// Zen Workspaces
pref('zen.workspaces.enabled', true);
pref('zen.workspaces.hide-deactivated-workspaces', false);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/base/content/ZenStartup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

// Disable smooth scroll
gBrowser.tabContainer.arrowScrollbox.smoothScroll = false;
gBrowser.tabContainer.arrowScrollbox.smoothScroll = Services.prefs.getBoolPref('zen.startup.smooth-scroll-in-tabs', false);

ZenWorkspaces.init();
gZenUIManager.init();
Expand Down
72 changes: 71 additions & 1 deletion src/browser/components/tabbrowser/content/tabs-js.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js
index f7c39fe804182e2bdf53045ba3b6a5ba17079fc3..93be23da305a5e2e51bff1c5b5f287439a8fafa8 100644
index f7c39fe804182e2bdf53045ba3b6a5ba17079fc3..bddba0cb7b475ca7a8d0e58227c62f82b62e118b 100644
--- a/browser/components/tabbrowser/content/tabs.js
+++ b/browser/components/tabbrowser/content/tabs.js
@@ -649,7 +649,7 @@
Expand Down Expand Up @@ -158,3 +158,73 @@ index f7c39fe804182e2bdf53045ba3b6a5ba17079fc3..93be23da305a5e2e51bff1c5b5f28743
return;
}

@@ -2726,12 +2730,14 @@
selectedTab = {
left: selectedTab.left,
right: selectedTab.right,
+ top: selectedTab.top,
+ bottom: selectedTab.bottom
};
}
return [
this._lastTabToScrollIntoView,
this.arrowScrollbox.scrollClientRect,
- { left: lastTabRect.left, right: lastTabRect.right },
+ lastTabRect,
selectedTab,
];
})
@@ -2748,8 +2754,13 @@
delete this._lastTabToScrollIntoView;
// Is the new tab already completely visible?
if (
- scrollRect.left <= tabRect.left &&
- tabRect.right <= scrollRect.right
+ this.verticalMode ? (
+ scrollRect.top <= tabRect.top &&
+ tabRect.bottom <= scrollRect.bottom
+ ) : (
+ scrollRect.left <= tabRect.left &&
+ tabRect.right <= scrollRect.right
+ )
) {
return;
}
@@ -2758,19 +2769,30 @@
// Can we make both the new tab and the selected tab completely visible?
if (
!selectedRect ||
- Math.max(
- tabRect.right - selectedRect.left,
- selectedRect.right - tabRect.left
- ) <= scrollRect.width
+ this.verticalMode ? (
+ Math.max(
+ tabRect.bottom - selectedRect.top,
+ selectedRect.bottom - tabRect.top
+ ) <= scrollRect.height
+ ) : (
+ Math.max(
+ tabRect.right - selectedRect.left,
+ selectedRect.right - tabRect.left
+ ) <= scrollRect.width
+ )
) {
this.arrowScrollbox.ensureElementIsVisible(tabToScrollIntoView);
return;
}

this.arrowScrollbox.scrollByPixels(
- this.#rtlMode
- ? selectedRect.right - scrollRect.right
- : selectedRect.left - scrollRect.left
+ this.verticalMode ? (
+ tabRect.top - selectedRect.top
+ ) : (
+ this.#rtlMode
+ ? selectedRect.right - scrollRect.right
+ : selectedRect.left - scrollRect.left
+ )
);
}

0 comments on commit d91c9dc

Please sign in to comment.