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