show active tab in quick tab switcher when in container mode

This commit is contained in:
Fabian Freund
2026-03-12 15:27:40 +01:00
parent 585fd7a362
commit 5486ae835a
3 changed files with 33 additions and 5 deletions
@@ -273,9 +273,11 @@ EquatableValue<List<TabStateWithContainer>> quickTabSwitcherTabStates(
ref.watch(selectedContainerTabStatesWithContainerProvider).value,
};
return EquatableValue(
tabStates.where((state) => state.$1.id != selectedTabId).toList(),
);
return EquatableValue(switch (effectiveMode) {
QuickTabSwitcherMode.lastUsedTabs =>
tabStates.where((state) => state.$1.id != selectedTabId).toList(),
QuickTabSwitcherMode.containerTabs => tabStates,
});
}
@Riverpod()
@@ -377,6 +377,7 @@ class BrowserTabBarView extends StatelessWidget {
class QuickTabSwitcherItem with FastEquatable {
final Color? color;
final String id;
final bool isActive;
final TabMode tabMode;
final bool isHistory;
final bool isPinned;
@@ -387,6 +388,7 @@ class QuickTabSwitcherItem with FastEquatable {
QuickTabSwitcherItem({
required this.color,
required this.id,
required this.isActive,
required this.tabMode,
required this.isHistory,
required this.isPinned,
@@ -399,6 +401,7 @@ class QuickTabSwitcherItem with FastEquatable {
List<Object?> get hashParameters => [
color,
id,
isActive,
tabMode,
isHistory,
isPinned,
@@ -435,19 +438,21 @@ class QuickTabSwitcher extends HookConsumerWidget {
final tabStates = ref.watch(
quickTabSwitcherTabStatesProvider(quickTabSwitcherMode),
);
final selectedTabId = ref.watch(selectedTabProvider);
final historySuggestions = ref
.watch(quickTabSwitcherHistorySuggestionsProvider(quickTabSwitcherMode))
.value;
final availableItems = tabStates.value
.map<QuickTabSwitcherItem>(
(state) => QuickTabSwitcherItem(
color: state.$2?.color,
id: state.$1.id,
isActive: state.$1.id == selectedTabId,
title: state.$1.titleOrAuthority,
tabMode: state.$1.tabMode,
isHistory: false,
isPinned: pinnedTabIds?.contains(state.$1.id) ?? false,
url: state.$1.url,
color: state.$2?.color,
avatar: TabIcon(tabState: state.$1, iconSize: 20),
),
)
@@ -456,27 +461,38 @@ class QuickTabSwitcher extends HookConsumerWidget {
final url = Uri.parse(state.url);
return QuickTabSwitcherItem(
color: null,
id: state.url,
isActive: false,
title: state.title ?? url.authority,
tabMode: TabMode.regular,
isHistory: true,
isPinned: false,
url: url,
color: null,
avatar: UrlIcon([url], iconSize: 20),
);
}),
)
.toList();
final activeItem = availableItems.firstWhere(
(item) => item.isActive,
orElse: () => availableItems.first,
);
final chipScrollController = useScrollController();
return QuickTabSwitcherView(
availableItems: availableItems,
activeItem: activeItem.isActive ? activeItem : null,
scrollController: chipScrollController,
showTitles: showTitles,
showIsolatedTabUi: showIsolatedTabUi,
onSelected: (item) async {
if (!item.isHistory && item.isActive) {
return;
}
Future<void>? animation;
if (disableAnimations) {
chipScrollController.jumpTo(0);
@@ -533,6 +549,7 @@ class QuickTabSwitcherView extends StatelessWidget {
const QuickTabSwitcherView({
super.key,
required this.availableItems,
required this.activeItem,
required this.scrollController,
required this.showTitles,
required this.showIsolatedTabUi,
@@ -541,6 +558,7 @@ class QuickTabSwitcherView extends StatelessWidget {
});
final List<QuickTabSwitcherItem> availableItems;
final QuickTabSwitcherItem? activeItem;
final ScrollController scrollController;
final bool showTitles;
final bool showIsolatedTabUi;
@@ -564,8 +582,11 @@ class QuickTabSwitcherView extends StatelessWidget {
child:
SelectableChips<QuickTabSwitcherItem, QuickTabSwitcherItem, String>(
enableDelete: false,
sortSelectedFirst: false,
scrollController: scrollController,
itemId: (item) => item.id,
selectedItem: activeItem,
selectedBorderColor: Theme.of(context).colorScheme.primary,
labelPadding: (item) =>
(!showTitles &&
!item.isHistory &&
@@ -162,6 +162,7 @@ class _TabBarPreviewCard extends HookWidget {
final previewQuickItems = <QuickTabSwitcherItem>[
QuickTabSwitcherItem(
id: 'regular-preview-tab',
isActive: true,
title: 'News',
tabMode: TabMode.regular,
isHistory: false,
@@ -176,6 +177,7 @@ class _TabBarPreviewCard extends HookWidget {
),
QuickTabSwitcherItem(
id: 'private-preview-tab',
isActive: false,
title: 'Private',
tabMode: TabMode.private,
isHistory: false,
@@ -187,6 +189,7 @@ class _TabBarPreviewCard extends HookWidget {
if (settings.showIsolatedTabUi)
QuickTabSwitcherItem(
id: 'isolated-preview-tab',
isActive: false,
title: 'Bank',
tabMode: TabMode.isolated('preview-isolated-context'),
isHistory: false,
@@ -198,6 +201,7 @@ class _TabBarPreviewCard extends HookWidget {
if (settings.quickTabSwitcherShowHistorySuggestions)
QuickTabSwitcherItem(
id: 'history-preview-tab',
isActive: false,
title: 'Search',
tabMode: TabMode.regular,
isHistory: true,
@@ -225,6 +229,7 @@ class _TabBarPreviewCard extends HookWidget {
Widget buildQuickTabSwitcher() {
return QuickTabSwitcherView(
availableItems: previewQuickItems,
activeItem: previewQuickItems.firstWhere((item) => item.isActive),
scrollController: quickTabsController,
showTitles: settings.quickTabSwitcherShowTitles,
showIsolatedTabUi: settings.showIsolatedTabUi,