@@ -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 ;
0 commit comments