Chat: hide the chat list entirely (Ctrl+B / Cmd+B), per device

ListDetailPanes takes listHidden and slides the list to zero width (at once
with reduced motion), keeping its expanded or compact mode for when it comes
back. A wide chat offers Hide chat list in the list's bar and the pane menu,
Ctrl+B (Cmd+B on Apple; a focused terminal keeps Ctrl+B) and, while hidden,
a Show chat list button at the start of the top-left pane's bar. The choice
is device-local (pipelines.chat.listHidden.v1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 21:33:05 +00:00
parent 22ab20077b
commit 109ea72252
15 changed files with 631 additions and 11 deletions
@@ -24,6 +24,7 @@ class ChatPanePlacement {
this.pasteTarget = false,
this.ownsPasteWhenFocused = false,
this.paneControls,
this.leadingControl,
this.paneCommands,
this.onComposerFocus,
this.onNextChat,
@@ -54,6 +55,10 @@ class ChatPanePlacement {
/// The pane menu's choices, built in the pane's own context.
final List<Widget> Function(BuildContext paneContext)? paneControls;
/// The bar's leading control where it shows no Back, built in the pane's
/// own context; null for none.
final Widget? Function(BuildContext paneContext)? leadingControl;
/// Choices the chat list hands to this chat's conversation to run.
final ChatPaneCommands? paneCommands;
final VoidCallback? onComposerFocus;
@@ -117,6 +122,7 @@ Widget buildChatPaneContent({
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
showBackButton: placement.showBackButton,
paneControls: placement.paneControls?.call(context) ?? const [],
leadingControl: placement.leadingControl?.call(context),
paneCommands: placement.paneCommands,
onComposerFocus: placement.onComposerFocus,
onComposerReady: (composer) =>
@@ -0,0 +1,62 @@
part of 'screen.dart';
/// Hiding the wide layout's chat list entirely (Ctrl+B, the pane menu, the
/// list's own bar), and the button that brings it back.
mixin _ChatScreenListToggle on State<ChatScreen> {
ChatComposerFocusRequests get _composerFocus;
ChatWorkspaceController get _workspace;
late final ChatListHiddenController _listHidden =
widget.listHidden ?? ChatListHiddenController.instance;
/// Whether the list is hidden beside an open chat. With no chat open the
/// list is the page, so it always shows.
bool _listHiddenBeside(String? selected) =>
selected != null && _listHidden.value;
void _bindListHidden() {
_listHidden.addListener(_listHiddenChanged);
unawaited(_listHidden.restore());
}
void _unbindListHidden() => _listHidden.removeListener(_listHiddenChanged);
void _listHiddenChanged() {
if (mounted) setState(() {});
}
/// Shows or hides the list. Hiding gives the keyboard to the active chat,
/// since the list (and anything focused in it) goes away.
void _toggleChatList() {
final hiding = !_listHidden.value;
_listHidden.toggle();
final active = _workspace.activePane?.sessionId;
if (hiding && active != null) _composerFocus.request(active);
}
/// The pane menu's toggle, naming its shortcut.
ChatBarAction _chatListToggleAction() => ChatBarAction(
identifier: 'chat-list-toggle',
label: chatListToggleLabel(_listHidden.value),
onPressed: _toggleChatList,
materialIcon: _listHidden.value ? Icons.menu : Icons.menu_open,
);
/// The top bar's way back to a hidden list, at the start of the top left
/// pane's bar (the one beside where the list was); null elsewhere.
Widget? _showChatListButton(BuildContext paneContext, String? selected) {
if (!_listHiddenBeside(selected) || !showsListBesideDetail(context)) {
return null;
}
final scope = ChatWorkspacePaneScope.maybeOf(paneContext);
if (scope != null && (scope.leftEdgeShared || scope.topEdgeShared)) {
return null;
}
return IconButton(
key: const Key('chat-show-list'),
tooltip: chatListToggleLabel(true),
onPressed: _toggleChatList,
icon: const Icon(Icons.menu),
);
}
}
@@ -12,6 +12,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
void _back();
void _openRouted(String id);
bool get _pageOpen;
void _toggleChatList();
Widget _thread(ChatWorkspacePane pane);
ChatSidebarMode _sidebarMode = ChatSidebarMode.expanded;
@@ -513,6 +514,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
final id = _workspace.activePane?.sessionId;
if (id != null) _paneCommands.request(id, ChatPaneCommand.files);
},
onToggleList: _toggleChatList,
enabled: () =>
_workspaceVisible &&
_workspace.paneCount > 0 &&
@@ -50,6 +50,7 @@ class ChatThreadHeader extends StatelessWidget {
this.moreActions = const [],
this.chatColor,
this.identity,
this.leading,
});
final String title;
@@ -77,6 +78,10 @@ class ChatThreadHeader extends StatelessWidget {
/// The chat's identity avatar, shown in the title on a phone.
final Widget? identity;
/// A control at the bar's leading edge where there is no Back: the wide
/// layout's Show chat list while the list is hidden.
final Widget? leading;
@override
Widget build(BuildContext context) {
final tint = chatBarTintOf(context, chatColor);
@@ -125,7 +130,7 @@ class ChatThreadHeader extends StatelessWidget {
key: const Key('chat-back'),
onPressed: onBack,
)
: null,
: leading,
title: !showTitle ? '' : (title.isEmpty ? 'Chat' : title),
titleLeading: showTitle ? identity : null,
subtitle: showTitle ? ServerContext.metadata(context, folder) : null,
@@ -141,6 +141,7 @@ class ChatThreadView extends StatefulWidget {
this.paneCommands,
this.onComposerFocus,
this.sidebarControl,
this.leadingControl,
this.showBackButton,
this.useNativeBack = false,
this.pasteTarget = true,
@@ -159,6 +160,9 @@ class ChatThreadView extends StatefulWidget {
final ChatPaneCommands? paneCommands;
final VoidCallback? onComposerFocus;
final Widget? sidebarControl;
/// The header's leading control where it shows no Back (Show chat list).
final Widget? leadingControl;
final bool? showBackButton;
final bool useNativeBack;
final bool pasteTarget;
@@ -1682,6 +1686,7 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
? null
: ChatSessionAvatar(session: session, selected: true),
onInfo: _openInfo,
leading: widget.leadingControl,
showTitle: !inWindow,
showBack: canGoBack,
// A pushed page keeps the platform's stock Back (pop this route); a
+23 -3
View File
@@ -49,6 +49,7 @@ import 'stack/mobile_chat_navigation.dart';
import 'workspace/chat_center_stage_action.dart';
import 'workspace/chat_center_stage_controller.dart';
import 'workspace/chat_center_stage_keys.dart';
import 'workspace/chat_list_hidden_controller.dart';
import 'workspace/chat_pane_move_actions.dart';
import 'workspace/chat_pane_move_shortcuts.dart';
import 'workspace/chat_workspace_entrance.dart';
@@ -71,6 +72,7 @@ part 'chat_screen_attention.dart';
part 'chat_screen_float.dart';
part 'chat_screen_pane_menu.dart';
part 'chat_screen_keys.dart';
part 'chat_screen_list_toggle.dart';
part 'chat_screen_quick_switch.dart';
part 'chat_screen_stack.dart';
part 'chat_screen_workspace.dart';
@@ -96,6 +98,7 @@ class ChatScreen extends StatefulWidget {
this.persistWorkspace = false,
this.runtime,
this.windows,
this.listHidden,
});
final ApiGateway gateway;
@@ -109,6 +112,10 @@ class ChatScreen extends StatefulWidget {
/// float).
final ChatWindows? windows;
/// Whether a wide layout hides its chat list beside an open chat; the
/// device's own choice ([ChatListHiddenController.instance]) when null.
final ChatListHiddenController? listHidden;
/// The chat session the current route names, or null for the list.
final String? initialSessionId;
@@ -133,7 +140,8 @@ class _ChatScreenState extends State<ChatScreen>
_ChatScreenPaneMenu,
_ChatScreenQuickSwitch,
_ChatScreenAttention,
_ChatScreenStack {
_ChatScreenStack,
_ChatScreenListToggle {
/// The chats' shared state: the list, opened rows, accepted models,
/// transcript positions and caches (see [ChatRuntime]).
@override
@@ -174,6 +182,7 @@ class _ChatScreenState extends State<ChatScreen>
_bindWindows();
_bindQuickSwitch();
_bindAttention();
_bindListHidden();
final initial = widget.initialSessionId;
if (initial != null && initial.isNotEmpty) {
_workspace.open(initial);
@@ -481,6 +490,7 @@ class _ChatScreenState extends State<ChatScreen>
_unbindWindows();
_unbindQuickSwitch();
_unbindAttention();
_unbindListHidden();
_workspace.removeListener(_workspaceChanged);
_workspace.dispose();
_sessions.removeListener(_nextChanged);
@@ -517,12 +527,16 @@ class _ChatScreenState extends State<ChatScreen>
showBackButton: _page.open || !showsListBesideDetail(context),
paneCommands: _paneCommands,
onComposerFocus: () => _composerFocus.request(selected),
leadingControl: (paneContext) =>
_showChatListButton(paneContext, _selected),
paneControls: (paneContext) => [
ChatBarAction(
label: 'Add chat pane',
onPressed: () => _addPane(paneContext),
materialIcon: Icons.add_box_outlined,
),
if (showsListBesideDetail(context) && !_page.open)
_chatListToggleAction(),
if (_workspace.paneCount > 1 && showsListBesideDetail(context))
chatCenterStageAction(ChatCenterStageController.instance),
...chatPaneMoveActions(
@@ -588,8 +602,10 @@ class _ChatScreenState extends State<ChatScreen>
publishShellBar:
(selected == null ||
!beside ||
_sidebarMode == ChatSidebarMode.expanded) &&
(_sidebarMode == ChatSidebarMode.expanded &&
!_listHiddenBeside(selected))) &&
(beside || !_usedWorkspace || selected == null),
onHideList: beside && selected != null ? _toggleChatList : null,
);
final fullList = ContainerTransformScope(
sources: _rowSources,
@@ -637,11 +653,15 @@ class _ChatScreenState extends State<ChatScreen>
);
}
return ShellBar(
active: selected != null && _sidebarMode != ChatSidebarMode.expanded,
active:
selected != null &&
(_sidebarMode != ChatSidebarMode.expanded ||
_listHiddenBeside(selected)),
barless: true,
hideNavigation: true,
child: ListDetailPanes(
list: list,
listHidden: _listHiddenBeside(selected),
compactListWidth: selected == null ? null : ChatCompactSidebar.width,
onListCompactChanged: selected == null
? null
@@ -25,6 +25,7 @@ import 'create_chat_dialog.dart';
import 'rename_chat_dialog.dart';
import 'session_actions.dart';
import 'session_pane_menu.dart';
import '../../workspace/chat_list_hidden_controller.dart';
/// Browses server-owned sessions. Opening a row is read-only at this layer.
class ChatSessionsScreen extends StatefulWidget {
@@ -47,6 +48,7 @@ class ChatSessionsScreen extends StatefulWidget {
this.visibleSessionIds = const {},
this.publishShellBar,
this.folds,
this.onHideList,
});
final ApiGateway gateway;
final void Function(JsonMap session) onOpen;
@@ -87,6 +89,10 @@ class ChatSessionsScreen extends StatefulWidget {
/// ready without pretending its open conversation is unread/inactive.
final bool? publishShellBar;
/// Hides the list beside the open chat (the wide layout's Hide chat
/// list); null offers no such action.
final VoidCallback? onHideList;
/// Overrides the device-local hidden/read store in tests.
final ChatSessionLocalStore? localStore;
@@ -440,6 +446,14 @@ class ChatSessionsScreenState extends State<ChatSessionsScreen> {
materialIcon: Icons.refresh,
),
?terminal,
if (widget.onHideList case final hide?)
ChatBarAction(
key: const Key('chat-hide-list'),
identifier: 'chat-hide-list',
label: chatListToggleLabel(false),
onPressed: hide,
materialIcon: Icons.menu_open,
),
];
}
}
@@ -6,9 +6,12 @@ import 'package:flutter/widgets.dart';
import '../../../ui/input/keyboard_owner.dart';
import '../windows/chat_window_tabs.dart';
import 'chat_center_stage_controller.dart';
import 'chat_list_hidden_controller.dart';
void _ignoreFilesShortcut() {}
void _ignoreListShortcut() {}
/// Answers the center-stage chord before any focused widget sees it, so it
/// works from the composer, the sidebar or a toolbar, and the focused field
/// never types it. Handling the app-owned chords also stops a browser's own
@@ -24,6 +27,7 @@ class ChatCenterStageKeys extends StatefulWidget {
required this.controller,
required this.enabled,
this.onToggleFiles = _ignoreFilesShortcut,
this.onToggleList = _ignoreListShortcut,
required this.child,
});
@@ -33,6 +37,9 @@ class ChatCenterStageKeys extends StatefulWidget {
/// no popup or other destination over it.
final bool Function() enabled;
final VoidCallback onToggleFiles;
/// Shows or hides the chat list (Ctrl+B, Cmd+B on Apple platforms).
final VoidCallback onToggleList;
final Widget child;
@override
@@ -68,6 +75,15 @@ class _ChatCenterStageKeysState extends State<ChatCenterStageKeys> {
}
return KeyEventResult.handled;
}
if (chatListToggleShortcut(event, keyboard)) {
// Ctrl+B stays the terminal's (tmux's prefix, the shell's back a
// character) while it has the keyboard; Cmd+B works there too.
if (!chatCenterStageUsesCommand() && primaryFocusIsTypingSurface()) {
return KeyEventResult.ignored;
}
if (event is KeyDownEvent) widget.onToggleList();
return KeyEventResult.handled;
}
if (!chatCenterStageShortcut(event, keyboard)) {
return KeyEventResult.ignored;
}
@@ -0,0 +1,121 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'chat_center_stage_controller.dart';
const chatListHiddenPreferenceKey = 'pipelines.chat.listHidden.v1';
abstract interface class ChatListHiddenStore {
Future<bool?> load();
Future<bool> save(bool hidden);
}
class SharedChatListHiddenStore implements ChatListHiddenStore {
const SharedChatListHiddenStore();
@override
Future<bool?> load() async {
try {
return (await SharedPreferences.getInstance()).getBool(
chatListHiddenPreferenceKey,
);
} on Object {
return null;
}
}
@override
Future<bool> save(bool hidden) async {
try {
return await (await SharedPreferences.getInstance()).setBool(
chatListHiddenPreferenceKey,
hidden,
);
} on Object {
return false;
}
}
}
/// An in-memory store for tests and fixtures.
class MemoryChatListHiddenStore implements ChatListHiddenStore {
MemoryChatListHiddenStore([this.hidden]);
bool? hidden;
@override
Future<bool?> load() async => hidden;
@override
Future<bool> save(bool hidden) async {
this.hidden = hidden;
return true;
}
}
/// Whether a wide Chat screen hides its chat list entirely while a chat is
/// open, giving the open chats the whole width. Device-local, like center
/// stage: a presentation choice, not part of any server's layout. The
/// expanded or compact list comes back as it was when shown again.
class ChatListHiddenController extends ValueNotifier<bool> {
ChatListHiddenController({ChatListHiddenStore? store})
: _store = store ?? const SharedChatListHiddenStore(),
super(false);
static final instance = ChatListHiddenController();
final ChatListHiddenStore _store;
int _revision = 0;
bool _restored = false;
/// Reads the saved choice once, unless it was changed meanwhile.
Future<void> restore() async {
if (_restored) return;
_restored = true;
final revision = _revision;
final saved = await _store.load();
if (saved != null && revision == _revision) super.value = saved;
}
/// An explicit choice, even of the current value, outranks a restore
/// still reading the stored one.
@override
set value(bool hidden) {
_revision++;
if (hidden == value) return;
super.value = hidden;
unawaited(_store.save(hidden));
}
void toggle() => value = !value;
}
/// Whether [event] shows or hides the chat list: Ctrl+B (Cmd+B on Apple
/// platforms), as an editor's sidebar toggle. Repeats of a held chord match
/// too, so they are swallowed; only the first press toggles.
bool chatListToggleShortcut(
KeyEvent event,
HardwareKeyboard keyboard, {
TargetPlatform? platform,
}) {
if (event is KeyUpEvent ||
event.physicalKey != PhysicalKeyboardKey.keyB ||
keyboard.isShiftPressed ||
keyboard.isAltPressed) {
return false;
}
return chatCenterStageUsesCommand(platform)
? keyboard.isMetaPressed && !keyboard.isControlPressed
: keyboard.isControlPressed && !keyboard.isMetaPressed;
}
/// The shortcut as this platform shows it, for menus and tooltips.
String chatListToggleShortcutLabel([TargetPlatform? platform]) =>
chatCenterStageUsesCommand(platform) ? 'Cmd+B' : 'Ctrl+B';
/// The toggle's label, naming its keyboard shortcut.
String chatListToggleLabel(bool hidden, [TargetPlatform? platform]) =>
'${hidden ? 'Show chat list' : 'Hide chat list'} '
'(${chatListToggleShortcutLabel(platform)})';
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import '../chat/workspace/chat_center_stage_controller.dart';
import '../chat/workspace/chat_float_shortcut.dart';
import '../chat/workspace/chat_list_hidden_controller.dart';
import '../terminal/terminal_shortcuts.dart';
import '../../shell/detached/detached_window_scope.dart';
import '../../shell/windows/window_shortcuts.dart';
@@ -162,6 +163,14 @@ class KeyboardShortcutRegistry {
action: 'Toggle Files',
keys: _apple ? 'Cmd+E' : 'Ctrl+E',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Show or hide the chat list',
keys: chatListToggleShortcutLabel(platform),
caveat: _apple
? 'Beside an open chat on a wide window.'
: 'Beside an open chat on a wide window. In the terminal Ctrl+B goes to the terminal.',
),
KeyboardShortcutEntry(
group: KeyboardShortcutGroup.chat,
action: 'Toggle Center Stage',
+37 -7
View File
@@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../ui/adaptive/floating_bar_layout.dart';
import '../ui/motion/motion.dart';
import 'detail_pane_navigator.dart';
import 'list_detail_policy.dart';
import 'list_pane_divider.dart';
@@ -99,6 +100,7 @@ class ListDetailPanes extends StatefulWidget {
this.listWidthOverride,
this.compactListWidth,
this.onListCompactChanged,
this.listHidden = false,
});
final Widget list;
@@ -110,6 +112,10 @@ class ListDetailPanes extends StatefulWidget {
/// The grab handle remains available at the rail edge to expand it again.
final double? compactListWidth;
final ValueChanged<bool>? onListCompactChanged;
/// Whether the list is hidden entirely: it slides to zero width (at once
/// with reduced motion) and comes back at the width it had.
final bool listHidden;
final Widget detail;
/// Which item [detail] shows; selecting another item closes any page the
@@ -120,13 +126,32 @@ class ListDetailPanes extends StatefulWidget {
State<ListDetailPanes> createState() => _ListDetailPanesState();
}
class _ListDetailPanesState extends State<ListDetailPanes> {
class _ListDetailPanesState extends State<ListDetailPanes>
with SingleTickerProviderStateMixin {
// Outside a shell (no [ListPaneWidthsScope]) the divider still drags; the
// width lasts as long as the panes.
ListPaneWidths? _ownWidths;
/// How far the list has slid away: 0 shown, 1 hidden.
late final AnimationController _hidden = AnimationController(
vsync: this,
value: widget.listHidden ? 1 : 0,
);
@override
void didUpdateWidget(ListDetailPanes oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.listHidden == oldWidget.listHidden) return;
_hidden.animateTo(
widget.listHidden ? 1 : 0,
duration: Motion.of(context, Motion.standard),
curve: Motion.curve,
);
}
@override
void dispose() {
_hidden.dispose();
_ownWidths?.dispose();
super.dispose();
}
@@ -141,7 +166,7 @@ class _ListDetailPanesState extends State<ListDetailPanes> {
final split = ShellBar.available(context);
return ShellPaneSplit(
child: ListenableBuilder(
listenable: widths,
listenable: Listenable.merge([widths, _hidden]),
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final window = ShellRailScope.windowWidth(context);
@@ -171,14 +196,19 @@ class _ListDetailPanesState extends State<ListDetailPanes> {
preferred != null
? preferred.clamp(compactThreshold, normalBounds.max).toDouble()
: listDetailListWidth(window, available, preferred);
final listWidth = (widget.listWidthOverride ?? normalWidth)
final shownWidth = (widget.listWidthOverride ?? normalWidth)
.clamp(0.0, math.max(0.0, available - kDetailPaneMinWidth))
.toDouble();
final hidden = _hidden.value;
final listWidth = shownWidth * (1 - hidden);
final lineWidth = listWidth > 0 ? 1.0 : 0.0;
final bodyWidth = math.max(0.0, available - lineWidth - listWidth);
// The list keeps its width while it slides, so it moves out
// rather than reflowing.
final retainedWidth = widget.listWidthOverride == null
? listWidth
? shownWidth
: math.max(normalWidth, kListPaneMinWidth);
final listGone = listWidth == 0 || widget.listHidden;
void resize(double value) {
widths.preview(key, value);
widget.onListCompactChanged?.call(value < compactThreshold);
@@ -225,9 +255,9 @@ class _ListDetailPanesState extends State<ListDetailPanes> {
minWidth: retainedWidth,
maxWidth: retainedWidth,
child: ExcludeFocus(
excluding: listWidth == 0,
excluding: listGone,
child: ExcludeSemantics(
excluding: listWidth == 0,
excluding: listGone,
child: SizedBox.expand(
key: const ValueKey('list-detail-list'),
child: Semantics(
@@ -257,7 +287,7 @@ class _ListDetailPanesState extends State<ListDetailPanes> {
),
],
),
if (bounds != null)
if (bounds != null && hidden == 0)
PositionedDirectional(
start: listWidth + 0.5 - kListPaneDividerGrabWidth / 2,
top: 0,
@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'chat_registration_test.dart'
@@ -269,4 +270,31 @@ void main() {
},
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
testWidgets('with the chat list hidden the switcher still opens and '
'switches', (tester) async {
final hidden = ChatListHiddenController.instance;
hidden.value = true;
addTearDown(() => hidden.value = false);
final provider = _provider();
final channel = await _mountOnChat(tester, provider);
expect(find.byKey(const Key('chat-show-list')), findsOneWidget);
await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(_field, findsOneWidget);
await tester.enterText(_field, 'second');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await replySubscribe(tester, channel, index: 1);
await replyHistory(tester, channel, index: 1);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s2');
expect(_composerFocused(tester, 's2'), isTrue);
// Switching leaves the list hidden.
expect(hidden.value, isTrue);
expect(find.byKey(const Key('chat-show-list')), findsOneWidget);
expect(tester.takeException(), isNull);
await _teardown(tester);
});
}
@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
{'id': 'a', 'title': 'First chat'},
{'id': 'b', 'title': 'Second chat'},
{'id': 'c', 'title': 'Third chat'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
final _body = find.byKey(const ValueKey('list-detail-body'));
final _show = find.byKey(const Key('chat-show-list'));
Future<ChatListHiddenController> _open(
WidgetTester tester, {
bool hidden = false,
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final listHidden = ChatListHiddenController(
store: MemoryChatListHiddenStore(hidden),
);
addTearDown(listHidden.dispose);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: gateway, listHidden: listHidden),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('First chat'));
await tester.pumpAndSettle();
return listHidden;
}
Future<void> _chord(WidgetTester tester, LogicalKeyboardKey key) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
double _railRight(WidgetTester tester) =>
tester.getRect(find.byType(NavigationRail)).right;
String? _active(WidgetTester tester) => tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller
.activePane
?.sessionId;
void main() {
testWidgets('Ctrl+B hides the list entirely and Show chat list brings it '
'back', (tester) async {
final listHidden = await _open(tester);
final shown = tester.getRect(_body).left;
expect(shown, greaterThan(_railRight(tester) + 100));
expect(_show, findsNothing);
// The list's own bar offers hiding too.
expect(find.byKey(const Key('chat-hide-list')), findsOneWidget);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
// The open chat takes the whole width beside the rail; no divider is
// left to drag.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(find.byType(ListPaneDivider), findsNothing);
expect(find.text('Second chat').hitTestable(), findsNothing);
// The chat's top bar starts with the way back.
expect(_show, findsOneWidget);
final bar = tester.getRect(find.byKey(const Key('chat-thread-header')));
expect(tester.getRect(_show).left - bar.left, lessThan(24));
await tester.tap(_show);
await tester.pumpAndSettle();
expect(listHidden.value, isFalse);
expect(tester.getRect(_body).left, closeTo(shown, 1));
expect(_show, findsNothing);
expect(find.text('Second chat').hitTestable(), findsOneWidget);
// Ctrl+B again hides, and again shows.
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isFalse);
expect(tester.takeException(), isNull);
});
testWidgets('the pane menu names the toggle and its shortcut', (
tester,
) async {
final listHidden = await _open(tester);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Hide chat list (Ctrl+B)'));
await tester.pumpAndSettle();
expect(listHidden.value, isTrue);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
expect(find.text('Show chat list (Ctrl+B)'), findsOneWidget);
});
testWidgets('a stored hidden list stays hidden, and Ctrl+Tab still cycles '
'the chats', (tester) async {
await _open(tester, hidden: true);
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(_show, findsOneWidget);
expect(_active(tester), 'a');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'b');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'c');
// Still hidden.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
});
}
@@ -0,0 +1,82 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';
KeyDownEvent _b() => const KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyB,
logicalKey: LogicalKeyboardKey.keyB,
timeStamp: Duration.zero,
);
void main() {
test('the choice is kept per device and restored', () async {
SharedPreferences.setMockInitialValues({});
final first = ChatListHiddenController();
expect(first.value, isFalse);
first.toggle();
expect(first.value, isTrue);
await Future<void>.delayed(Duration.zero);
expect(
(await SharedPreferences.getInstance()).getBool(
chatListHiddenPreferenceKey,
),
isTrue,
);
final next = ChatListHiddenController();
await next.restore();
expect(next.value, isTrue);
});
test('a choice made while restoring wins', () async {
final store = MemoryChatListHiddenStore(true);
final controller = ChatListHiddenController(store: store);
final restoring = controller.restore();
controller.value = false;
await restoring;
expect(controller.value, isFalse);
});
testWidgets('Ctrl+B elsewhere, Cmd+B on Apple; no other chord', (
tester,
) async {
final keyboard = HardwareKeyboard.instance;
Future<bool> matches(
List<LogicalKeyboardKey> modifiers,
TargetPlatform platform,
) async {
for (final key in modifiers) {
await tester.sendKeyDownEvent(key);
}
final result = chatListToggleShortcut(_b(), keyboard, platform: platform);
for (final key in modifiers.reversed) {
await tester.sendKeyUpEvent(key);
}
return result;
}
const linux = TargetPlatform.linux;
const mac = TargetPlatform.macOS;
expect(await matches([LogicalKeyboardKey.controlLeft], linux), isTrue);
expect(await matches([LogicalKeyboardKey.metaLeft], mac), isTrue);
expect(await matches([LogicalKeyboardKey.controlLeft], mac), isFalse);
expect(await matches([LogicalKeyboardKey.metaLeft], linux), isFalse);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.shiftLeft,
], linux),
isFalse,
);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.altLeft,
], linux),
isFalse,
);
expect(await matches(const [], linux), isFalse);
expect(chatListToggleLabel(true, linux), 'Show chat list (Ctrl+B)');
expect(chatListToggleLabel(false, mac), 'Hide chat list (Cmd+B)');
});
}
+73
View File
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
final _body = find.byKey(const ValueKey('list-detail-body'));
Widget _panes({required bool hidden, bool reduceMotion = false}) => MaterialApp(
home: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
child: Scaffold(
body: ListDetailPanes(
listHidden: hidden,
list: const Focus(
autofocus: true,
child: Text('The list', key: Key('list-text')),
),
detail: const SizedBox.expand(),
),
),
),
),
);
void _size(WidgetTester tester) {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
void main() {
testWidgets('a hidden list slides to zero width and comes back as it was', (
tester,
) async {
_size(tester);
await tester.pumpWidget(_panes(hidden: false));
await tester.pumpAndSettle();
final shown = tester.getRect(_body).left;
expect(shown, greaterThan(200));
expect(find.byType(ListPaneDivider), findsOneWidget);
await tester.pumpWidget(_panes(hidden: true));
await tester.pump(const Duration(milliseconds: 60));
final sliding = tester.getRect(_body).left;
expect(sliding, inExclusiveRange(0, shown), reason: 'animates');
// The handle is not offered while the list slides or is hidden.
expect(find.byType(ListPaneDivider), findsNothing);
await tester.pumpAndSettle();
expect(tester.getRect(_body).left, 0);
expect(tester.getRect(_body).width, 1200);
// Nothing in the hidden list keeps the keyboard.
final listFocus = Focus.of(
tester.element(find.byKey(const Key('list-text'))),
);
expect(listFocus.hasFocus, isFalse);
await tester.pumpWidget(_panes(hidden: false));
await tester.pumpAndSettle();
expect(tester.getRect(_body).left, shown);
expect(find.byType(ListPaneDivider), findsOneWidget);
});
testWidgets('with reduced motion the list hides at once', (tester) async {
_size(tester);
await tester.pumpWidget(_panes(hidden: false, reduceMotion: true));
await tester.pumpAndSettle();
await tester.pumpWidget(_panes(hidden: true, reduceMotion: true));
await tester.pump();
await tester.pump();
expect(tester.getRect(_body).left, 0);
});
}