Skip to content

Commit 54c58ab

Browse files
committed
Add config for max visible cards
1 parent 9f719b4 commit 54c58ab

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

prefs/zen/zen.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@
6565

6666
- name: zen.tabs.tab-switcher.use-recent-order
6767
value: false
68+
69+
- name: zen.tabs.tab-switcher.max-visible-cards
70+
value: 5

src/zen/tabs/ZenTabSwitcher.mjs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class nsZenTabSwitcher extends nsZenDOMOperatedFeature {
1616
#ctrlPressed = false;
1717
#lazyPrefs = {};
1818
#recentlyUsedTabs = []; // Track recently used tabs ourselves
19+
#actualVisibleCards = 5; // Actual number of cards visible (updated on render)
1920

2021
init() {
2122
console.log("ZenTabSwitcher: Initializing...");
@@ -410,18 +411,29 @@ class nsZenTabSwitcher extends nsZenDOMOperatedFeature {
410411

411412
const totalTabs = this.#tabList.length;
412413

413-
// Responsive max visible cards based on viewport width
414-
// 5 cards: >1300px, 4 cards: >1050px, 3 cards: >800px, 2 cards: >550px, 1 card: <=550px
415-
const maxVisible = this.#getMaxVisibleCards();
416-
417-
// Set fixed width to show cards based on viewport size (or fewer if we have fewer tabs)
418-
// This creates the viewport that shows the appropriate number of cards
419-
const visibleCount = Math.min(totalTabs, maxVisible);
414+
// Card dimensions
420415
const cardWidth = 200; // var(--zen-tab-switcher-card-width)
421416
const gap = 0; // var(--zen-tab-switcher-gap)
417+
const panelPadding = 23 * 2; // var(--zen-tab-switcher-padding) * 2
418+
419+
// Calculate maximum available width for cards (90vw minus panel padding)
420+
const maxAvailableWidth = window.innerWidth * 0.9 - panelPadding;
421+
422+
// Calculate how many full cards can actually fit in the available space
423+
const maxCardsThatFit = Math.floor((maxAvailableWidth + gap) / (cardWidth + gap));
424+
425+
// Get responsive max based on viewport breakpoints and user preference
426+
const maxVisibleFromBreakpoints = this.#getMaxVisibleCards();
422427

423-
// Calculate container width: 5 cards + 4 gaps (or fewer if less tabs)
428+
// Actual visible count is the minimum of: cards that fit, breakpoint max, total tabs
429+
const visibleCount = Math.min(totalTabs, maxVisibleFromBreakpoints, maxCardsThatFit);
430+
431+
// Calculate container width based on actual visible count
424432
const containerWidth = (cardWidth * visibleCount) + (gap * (visibleCount - 1));
433+
434+
// Store the actual visible count for pagination logic
435+
this.#actualVisibleCards = visibleCount;
436+
425437
this.tabsContainer.style.width = `${containerWidth}px`;
426438
this.tabsContainer.style.maxWidth = `${containerWidth}px`;
427439

@@ -611,24 +623,31 @@ class nsZenTabSwitcher extends nsZenDOMOperatedFeature {
611623
}
612624

613625
#getMaxVisibleCards() {
614-
let maxVisible = 5;
626+
// Get user preference for max cards (default 5, clamped to 10)
627+
const prefMax = Math.min(10, Math.max(1,
628+
Services.prefs.getIntPref("zen.tabs.tab-switcher.max-visible-cards", 5)
629+
));
630+
631+
// Responsive calculation based on viewport width
632+
let maxVisible = prefMax;
615633
const viewportWidth = window.innerWidth;
616634
if (viewportWidth <= 550) {
617635
maxVisible = 1;
618636
} else if (viewportWidth <= 800) {
619-
maxVisible = 2;
637+
maxVisible = Math.min(2, prefMax);
620638
} else if (viewportWidth <= 1050) {
621-
maxVisible = 3;
639+
maxVisible = Math.min(3, prefMax);
622640
} else if (viewportWidth <= 1300) {
623-
maxVisible = 4;
641+
maxVisible = Math.min(4, prefMax);
624642
}
625643

626644
return maxVisible;
627645
}
628646

629647
#getPageStartIndex(cardIndex) {
630648
const totalTabs = this.#tabList.length;
631-
const maxVisible = this.#getMaxVisibleCards();
649+
// Use the actual visible cards from the last render, not the theoretical max
650+
const maxVisible = this.#actualVisibleCards;
632651

633652
const currentPage = Math.floor(cardIndex / maxVisible);
634653
let pageStartIndex = currentPage * maxVisible;

src/zen/tabs/zen-tab-switcher.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@
8888
overflow-x: hidden; /* No overflow - perfectly symmetrical */
8989
overflow-y: hidden;
9090
/* width is set dynamically via JavaScript */
91+
max-width: 100%; /* Constrain within panel boundaries */
9192
scroll-behavior: smooth;
9293
scrollbar-width: none; /* Hide scrollbar */
9394
position: relative;
95+
box-sizing: border-box;
9496
}
9597

9698
#zen-tab-switcher-tabs::-webkit-scrollbar {

0 commit comments

Comments
 (0)